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

Should updateInstance have an argument? #1537

Closed
nikkhielseath opened this issue Oct 7, 2021 · 3 comments · Fixed by #2247
Closed

Should updateInstance have an argument? #1537

nikkhielseath opened this issue Oct 7, 2021 · 3 comments · Fixed by #2247

Comments

@nikkhielseath
Copy link

Description

If I want to update my PDF instance then, I need to send an argument to update it with something.
Like, a whole new document.

const [instance, updateInstance] = usePdf({
 document: defaultDocument
});

/* SOME OPERATION THAT LEADS TO A FULLY NEW PDF */
updateInstance({
 document: FULLY_NEW_DOCUMENT
})

But, this doesn't work. updateInstance doesn't seem to accept an argument. (I have linked the code below)

const update = () => {
pdfInstance.current.updateContainer(document);
};
return [state, update];
};

image

@dandresfg
Copy link

You need to try something like:

const [instance, updateInstance] = usePdf({ document:  <Document data={data} /> });

updateInstance() // This does not receive any argument, it just make another pdf file.

@nikkhielseath
Copy link
Author

@dandresfg

Yes, sir, I am aware of the same. But, I need to update the instance to render another Document and not the same one.

@nikkhielseath
Copy link
Author

nikkhielseath commented Oct 8, 2021

For example, while updating a state, I need to specify what to update the state to (I send that as an argument).
I was wondering if the same can be applied to this hook instance.

I can achieve this updating functionality if, I generate a PDF using PDFDownload Link and use a React state as the Document. (And update the state when necessary leading to change in the document's value) but then, I lose the fine-control that the usePDF hook provides.
Like, triggering an action on error or loading.

const [documentHolder, setDocumentHolder] = useState(<DefaultDocument />);

/** SOME OPERATIONS **/
if (user.type === 'sales' && user.permissions === 'admin'){
  setDocumentHolder(<TopSecretSalesDocument {...allTheRequiredProps} />)
}

return (
<SOME.PARENT>
  {documentHolder && <PDFDownloadLink document={documentHolder} />}
</SOME.PARENT>
)

^ This works and does enable us to change the document that is supposed to be rendered.

@nikkhielseath nikkhielseath changed the title Does updateInstance have an argument? Should updateInstance have an argument? Oct 9, 2021
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

Successfully merging a pull request may close this issue.

2 participants