Function components cannot be given refs. Attempts to access this ref will fail. Did you mean to use React.forwardRef()?
See original GitHub issueAfter update to latest tippy i’ve started to get this error. Reproduction case: Work’s fine:
<Tooltip content={'ам'}>
<div>1</div>
</Tooltip>
Got error:
<Tooltip content={'ам'} >
<Icon />
</Tooltip>
or
<Tooltip content={'ам'} >
1
</Tooltip>
Icon code:
export const Icon = props => (
<svg {...props}>
// svg image code
</svg>
)
Tooltip code:
import Tippy from '@tippy.js/react'
import React, { useEffect, useState } from 'react'
export function Tooltip({ children, sharedContent, content, pure, ...rest }) {
const [tip, tipSet] = useState(false)
useEffect(() => {
if (sharedContent) {
switch (sharedContent) {
case 'something':
content = (
<div>
shared tips
</div>
)
}
}
tipSet(content)
}, [content])
if (!tip) return false
return (
<Tippy content={tip} {...rest}>
{pure
? React.cloneElement(children)
: React.cloneElement(children, { className: 'tippy-target' })} // change cursor to one with question mark
</Tippy>
)
}
Tooltip.defaultProps = {
ignoreAttributes: true,
animateFill: false,
delay: [300, 0],
interactive: true,
animation: 'scale',
theme: 'knigAm',
duration: [300, 300],
distance: 5,
maxWidth: '330px',
sticky: true,
touchHold: true,
a11y: false
}
Any thoughts to try?
Issue Analytics
- State:
- Created 5 years ago
- Reactions:9
- Comments:11 (2 by maintainers)
Top Results From Across the Web
How do I avoid '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 ForwardRef . in NavLink (created...
Read more >Solved: Function components cannot be given refs ... - GitHub
Solved: Function components cannot be given refs. Attempts to access this ref will fail. Did you mean to use React.forwardRef()? #2120.
Read more >ref prop should not be used on React function components
React Warning: Function components cannot be given refs. Attempts to access this ref will fail. Did you mean to use React.forwardRef()?. Refs ......
Read more >warning: function components cannot be given refs. attempts ...
Iget error 'Function components cannot be given refs. Attempts to access this ref will fail. Did you mean to use React.forwardRef()?' . How...
Read more >Forwarding Refs - React
The second ref argument only exists when you define a component with React.forwardRef call. Regular function or class components don't receive the ref...
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

I think a lot of people are ending up on this issue (if GitHub search is accurate!)
The full solution, including a workaround for legacy components, is available on the README: https://github.com/atomiks/tippy.js-react#component-children
You need to use
forwardRefif you’re using a component as a child now. The internals were changed to removefindDOMNodewhich required this changeEdit: the docs are definitely missing this though, I forgot. I will add it in now 😀