How to forward refs?
See original GitHub issueAlright, so I have been trying to use and imported SVG with react-pose. React-pose has nothing to do with the problem. A simple example would be:
import ExpandSVG from './assets/expand.svg';
const ExpandIcon = React.forwardRef((props, ref) => (
<ExpandSVG ref={ref} />
));
function Example() {
const refExpandIcon = useRef(null);
function handleClick() {
console.log(refExpandIcon);
}
return (
<div>
<button
type="button"
onClick={handleClick}
>
Log ref of the Icon Below
</button>
<ExpandIcon ref={refExpandIcon} />
</div>
);
}
So when I click the button I would expect that the refExpandIcon would be anything but null. But instead I get a null;
Also I get the following error:
Removing the forwardRef
does not make a difference.
Any ideas? I feel like it is a super simple fix
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:5
Top Results From Across the Web
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 >How to use React's forwardRef function - Felix Gerschau
forwardRef is a helper function from React that allows us to forward a component's ref to another one. This tutorial will teach what...
Read more >ReactJS Forwarding Refs - GeeksforGeeks
The forwardRef method in React allows parent components to move down (or “forward”) refs to their children. ForwardRef gives a child ...
Read more >Using forwardRef in React to clean up the DOM
React forwardRef is a method that allows parent components pass down (i.e., “forward”) refs to their children. Using forwardRef in React gives ...
Read more >How can I use forwardRef() in React? - Stack Overflow
The only way to pass a ref to a function component is using forwardRef. When using forwardRef, you can simply pass 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 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
Can we please put this in 🙏? Happy to write a PR if needed
I think it’s a good idea. I wrote it in my message: