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.

Bug: OverlayTrigger + custom component = Warning: Function components cannot be given refs

See original GitHub issue

Prerequisites

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:closed
  • Created 2 years ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
alexandernstcommented, Aug 11, 2022

Cursor_y_NodeSettings_jsx_—_pipeline-builder

@GaylordP ^ I hope this helps

0reactions
GaylordPcommented, Aug 11, 2022

Thank you very much for these details 😃

Read more comments on GitHub >

github_iconTop 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 >

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