question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cannot read property 'dereference' of undefined

See original GitHub issue

I’m just trying a simple example to download a PDF with a PDFDownloadLink and its throwing the above error when the component renders.

const ReportPDF = () => (
        <Document>
            <Page size="A4">
                <View>
                    <Text>Section #1</Text>
                </View>
                <View>
                    <Text>Section #2</Text>
                </View>
            </Page>
        </Document>
    );
...
render  (
<div>
                                    <PDFDownloadLink document={<ReportPDF/>} fileName="somename.pdf">
                                        {({loading}) => loading ? <Button>Loading</Button> : <Button>PDF</Button>}
                                    </PDFDownloadLink>
                                </div>
)

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:14
  • Comments:33 (3 by maintainers)

github_iconTop GitHub Comments

54reactions
markpradhancommented, Jul 23, 2020

Apparently you should render it only once, so just use “useMemo”:

const DownloadPdf = () => {
  return useMemo(
    () => (
      <PDFDownloadLink document={<MyDocument />} fileName="some-nane.pdf">
        {({ loading }) => (loading ? 'loading...' : 'download')}
      </PDFDownloadLink>
    ),
    [],
  )
}
17reactions
andrioidcommented, Jun 26, 2019

I’ve been playing with react-pdf or around two weeks now and I mostly get these type of errors if rendering is interrupted.

Try preloading everything before trying to render with react-pdf. It seems that re-renders are a common cause for problems.

That includes fonts, images (urls are fine though), async data. Fetch it all in your container and THEN render the PDF for the best results.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Unhandled Rejection (TypeError): Cannot read property '' ...
You are trying to get a post with an id that doesn't exists. Looking at how .find works it will return undefined if...
Read more >
Cannot read properties of undefined (reading '0')
Specifically, this error occurs more often on our Data Deployer Application pages. Cause. You see this error because new orgs in Salesforce ......
Read more >
cannot read properties of undefined (reading 'datatransfer')
TypeError : Cannot read property 'setData' of undefined. The undefined here is the dataTransfer object. You can use the jest manual mocks to...
Read more >
7 Tips to Handle undefined in JavaScript
TypeError: 'undefined' is not a function; TypeError: Cannot read property '<prop-name>' of undefined; and alike type errors.
Read more >
Understanding reactivity
MobX reacts to any existing observable property that is read during the execution of a tracked function. "reading" is dereferencing an object's property, ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found