inputRef gives an error when passed an object, but isn't working when passed a function
See original GitHub issueI’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:
- Created 4 years ago
- Comments:8 (4 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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.
Will need to wait for a while for a release, I’m having slight problems with manual testing lately.