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

updateInstance doesn't update the current PDF when used in a useEffect #1376

Closed
DesignmonkeyJim opened this issue Jun 18, 2021 · 3 comments · Fixed by #2247
Closed

updateInstance doesn't update the current PDF when used in a useEffect #1376

DesignmonkeyJim opened this issue Jun 18, 2021 · 3 comments · Fixed by #2247
Labels

Comments

@DesignmonkeyJim
Copy link

Describe the bug
When you use the function updateInstance from usePDF in a useEffect to update and re-rendered the PDF, i doesn't seem to work

Code

const [update, setUpdate] = useState(false)

const [instance, updateInstance] = usePDF({
    document:
        <Document title="doc1">
            <Page >
                <View >
                   <Text>document 1</Text>
                </View>
            </Page>
        </Document>
});

useEffect(() => {
    if (update) {
        console.log('update to doc2')
        updateInstance({
            document: <Document title="doc2">
                <Page >
                    <View >
                         <Text>document 2</Text>
                    </View>
                </Page>
            </Document>
        })
    }
    setUpdate(true)

}, [update])

return instance.url && <object data={instance.url} type="application/pdf" height="100%" width="100%"></object>`

Expected behavior
I would have expected the PDF to re-render and show Document 2

Desktop (please complete the following information):

  • OS: MacOS
  • Browser chrome
  • React-pdf version 2.0.12
@pierrecazeneuve
Copy link

Hi, i tried like this and it works, i just replaced the setUpdate in your useEffect with false.

``
const [update, setUpdate] = useState(false)

const [instance, updateInstance] = usePDF({
    document: <EstimateTemplatePdf currentEstimate={currentEstimate}/>
});

useEffect(() => {
    if (update) {
        updateInstance({
            document: <EstimateTemplatePdf currentEstimate={currentEstimate}/>
        })
    }
    setUpdate(false)

}, [update])

@diegomura diegomura added the bug label Jul 25, 2021
@nikkhielseath
Copy link

@pierrecazeneuve and @DesignmonkeyJim

Does updateInstance accept an argument?

@gitname
Copy link

gitname commented Nov 4, 2022

Does updateInstance accept an argument?

According to the definition of usePDF (here: https://github.com/diegomura/react-pdf/blob/master/packages/renderer/src/dom/usePDF.js#L66-L71), the updateInstance function does not accept any arguments (by that, I mean that, when arguments are passed to the function, the function ignores them). The TypeScript type information for the usePDF hook (here: https://github.com/diegomura/react-pdf/blob/master/packages/renderer/index.d.ts#L472-L474) confirms that to me.

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

Successfully merging a pull request may close this issue.

5 participants