Bug: OverlayTrigger + custom component = Warning: Function components cannot be given refs
See original GitHub issuePrerequisites
- I am using the correct version of React-Bootstrap for my version of Bootstrap
- I have searched for duplicate or closed issues
- I have read the contributing guidelines
Describe the bug
I’m trying to use the OverlayTrigger
component by copying the code of one of the demos at https://react-bootstrap.github.io/components/overlays/#tooltips .
If I pass a <Button>
component as a child to the OverlayTrigger
component, the tooltip shows as expected, but if I pass a custom component (a component that just returns a simple div), I get this warning:
Warning: Function components cannot be given refs. Attempts to access this ref will fail.
Did you mean to use React.forwardRef()?
Check the render method of `OverlayTrigger`.
Expected behavior
I should be able to pass any components to OverlayTrigger
.
To Reproduce
Open the repro example I made.
Reproducible Example
https://codesandbox.io/s/distracted-robinson-kded3?file=/src/App.js
Screenshots
No response
What operating system(s) are you seeing the problem on?
macOS
What browser(s) are you seeing the problem on?
Chrome
What version of React-Bootstrap are you using?
2.1.1
What version of Bootstrap are you using?
5.1.3
Additional context
No response
Issue Analytics
- State:
- Created 2 years ago
- Comments:5
Top Results From Across the Web
javascript - Warning: Function components cannot be given refs
The error message suggests React.forwardRef might be the solution. Have you considered that? Have you looked up how it works? – Quentin. Mar...
Read more >Overlays | React-Bootstrap
Note that triggering components must be able to accept a ref since <OverlayTrigger> will attempt to add one. You can use forwardRef() for...
Read more >functional components cannot be given refs - You.com | The AI ...
I get the warning "Stateless function components cannot be given refs. Attempts to access this ref will fail" when trying to wrap my...
Read more >Function components cannot be given refs.“ error while using ...
Coding example for the question ”Warning: Function components cannot be given refs.“ error while using custom component in nextjs-Reactjs.
Read more >Function components cannot be given refs. Attempts to access ...
I started getting the below warning when i use Tooltip in my react application, ``` Warning: Function components cannot be given refs.
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 Free
Top 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
@GaylordP ^ I hope this helps
Thank you very much for these details 😃