Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changing file in the pdf component. #30

Closed
anedisi opened this issue Aug 29, 2017 · 4 comments
Closed

Changing file in the pdf component. #30

anedisi opened this issue Aug 29, 2017 · 4 comments

Comments

@anedisi
Copy link

anedisi commented Aug 29, 2017

This part in componentWillReceiveProps makes it so that that i can change the pdf if i change the file prop, the problem is that i have to use documentInitParameters because without that i cannot pass other parameters to getDocument. But if i change the url in documentInitParameters the component will not rerender because its allways asking it file,content or binaryContent have been changed and if not it will not trigger loadPDFDocument even with

(newDocInit && docInit && newDocInit.url !== docInit.url)))

because newSource and oldSource are the same.

const newDocInit = newProps.documentInitParameters;
const docInit = this.props.documentInitParameters;

// Only reload if the most significant source has changed!
let newSource = newProps.file;
let oldSource = newSource ? this.props.file : null;
newSource = newSource || newProps.binaryContent;
oldSource = newSource && !oldSource ? this.props.binaryContent : oldSource;
newSource = newSource || newProps.content;
oldSource = newSource && !oldSource ? this.props.content : oldSource;

if (newSource && newSource !== oldSource &&
  ((newProps.file && newProps.file !== this.props.file) ||
  (newProps.content && newProps.content !== this.props.content) ||
  (newDocInit && newDocInit !== docInit) ||
  (newDocInit && docInit && newDocInit.url !== docInit.url))) {
  this.loadPDFDocument(newProps);
}
@ThomasVuillaume
Copy link
Contributor

Same problem here, we sould correct this. I'll propose a pull request

@ThomasVuillaume
Copy link
Contributor

ThomasVuillaume commented Sep 19, 2017

just created #33

Edit: Ok, was too quick on this one. Makes it loop forever rendering the same pdf. Going to check and fix this.

@ThomasVuillaume
Copy link
Contributor

Ok I got this right now, tested and works fine !

Ready to merge

@mikecousins
Copy link
Owner

Thanks @ThomasVuillaume, I just merged it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants