-
-
Notifications
You must be signed in to change notification settings - Fork 10.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
(v3) Calling withRouter(Component, { withRef: true }) doesn't set the ref if there is no router prop available #5767
Comments
If you don't provide a router, what's the point of using withRouter? |
thanks for the quick response, @timdorr, in |
hmm, we were actually using feel free to close this, though I did find it a bit odd that the ref was obscured because of this. thanks for the help! |
I'm unsure if you're still accepting issues for v3, so feel free to close if not.
Version
3.2.0
Test Case
Happy to add if issues are still being accepted for v3.
Steps to reproduce
Rendering this component with no router means that the ref is never available in
getWrappedInstance()
(it always returnsundefined
).After some debugging, this looks like it's due to this short circuit https:/ReactTraining/react-router/blob/v3/modules/withRouter.js#L36 which was added in #4295 .
It's only after this short circuit that the ref callback is properly set and rendered.
https:/ReactTraining/react-router/blob/v3/modules/withRouter.js#L43
I'm happy to make a PR to supply the ref prop callback to the first return if changes are still being accepted!
The text was updated successfully, but these errors were encountered: