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.

inputRef gives an error when passed an object, but isn't working when passed a function

See original GitHub issue

I’m trying to call the innerHeight of the Document after loading, using the inputRef. This works if i do:

const previewRef = useRef() <Document inputRef={previewRef} … />

However, I get the following error: index.js:1375 Warning: Failed prop type: Invalid prop inputRef of type object supplied to Document, expected function

But when I try to pass the ref in as a function: <Document inputRef={ ref => previewRef = ref} />

previewRef.current is undefined.

Am I missing something?

Thanks

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

3reactions
wojtekmajcommented, Oct 5, 2020

@wojtekmaj what’s wrong with passing in the result of a React.createRef in v5?

After analysis, nothing really. At the moment of writing it’s only a problem in Page component, where inputRef is called like this:

https://github.com/wojtekmaj/react-pdf/blob/1f9ae5249aa2ff6f1c621d4867b5739388b4259e/src/Page.jsx#L366-L373

This, however, can easily be changed by using merge-refs library.

So that’s exactly what I did in b38ee57dea66f8801687662fd93cfa4374df7c03, which closes this issue.

2reactions
wojtekmajcommented, Oct 5, 2020

Will need to wait for a while for a release, I’m having slight problems with manual testing lately.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Getting TypeError when I'm passing a Ref from a function ...
I want to pass the ref from the App to Foo, App and Foo are function components, so I'm using forwardRef() to warp...
Read more >
Refs and the DOM - React
You can pass callback refs between components like you can with object refs that were created with React.createRef() . function CustomTextInput(props) { return ......
Read more >
The Guide to Learning React Hooks (Examples & Tutorials)
Learn all about React Hooks with this hands-on guide. Includes tutorials and code examples on using hooks for state and effects, for context...
Read more >
Using forwardRef in React to clean up the DOM
React forwardRef is a method that allows parent components pass down (i.e., ... To create a ref, React provides a function called React....
Read more >
ref keyword - C# Reference - Microsoft Learn
Don't confuse the concept of passing by reference with the concept of reference types. The two concepts are not the same. A method...
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