Use new forwardRef API in withRouter HOC
See original GitHub issueReact 16.3 is out and now we have an “official” way to pass ref through HOCs with new forwardRef API. Would you like to use it as a replacement for wrappedComponentRef prop to make wrapping transparent for parent components?
Can submit a PR.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:11
- Comments:21 (7 by maintainers)
Top Results From Across the Web
Use new forwardRef API in withRouter HOC #6056 - GitHub
React 16.3 is out and now we have an "official" way to pass ref through HOCs with new forwardRef API. Would you like...
Read more >Forward ref through React Router's withRouter HOC
Based on @Ranjith Kumar answer I came up with the following solution that: Is a bit shorter/simpler (no need for class component or...
Read more >Developers - Use new forwardRef API in withRouter HOC -
Use new forwardRef API in withRouter HOC. ... React 16.3 is out and now we have an "official" way to pass ref through...
Read more >Forwarding Refs - React
Forwarding refs in higher-order components The “logProps” HOC passes all props through to the component it wraps, so the rendered output will be...
Read more >react-router forwardref
forwardRef helps forward a ref through a Higher-order component to reference ... React's new "hooks" APIs give function components the ability to use...
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

Yes, we should update
withRouterto use theReact.forwardRefAPI. As @pshrmn noted above, we can’t do it in 4.x because it is compatible with React 15 and theforwardRefAPI was introduced in 16.3.We will fix this in version 5 when we upgrade our dep to React 16.7+.
As suggested in original SO question, here is a version built on @ranjith-s work, a bit simpler and that supports
displayNamewhich can be useful in tests or dev tools.