Receiving "Function components cannot be given refs." warning
See original GitHub issueI’m changing a component that was being wrapped by MenuProvider
to a function component, and am getting this warning.
Warning: Function components cannot be given refs. Attempts to access this ref will fail. Did you mean to use React.forwardRef()?
It still seems to work, however.
I didn’t see an existing issue for it.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:2
- Comments:7 (2 by maintainers)
Top Results From Across the Web
How do I avoid 'Function components cannot be given refs ...
Warning : Function components cannot be given refs. Attempts to access this ref will fail. Did you mean to use React.forwardRef()?.
Read more >Solved: Function components cannot be given refs ... - GitHub
A functional component isn't backed by an "instance" of anything, so it can't handle ref's passed to it automatically. BUT, if you wrap...
Read more >Forwarding Refs - React
Ref forwarding is an opt-in feature that lets some components take a ref they receive, and pass it further down (in other words,...
Read more >ref prop should not be used on React function components
This rule applies when a ref prop is specified on a React function component. The ref prop is used to provide a reference...
Read more >next link function components cannot be given refs. attempts ...
9. As the warning states you cannot assign refs to functional components without the usage of forwardRef. In order to have access to...
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
You could use a fragment in a pinch, that’s what I’m currently doing:
Apparently setting the
storeRef
prop tofalse
also removes the warning.