-
-
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
Improve withRouter #4838
Improve withRouter #4838
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is some good stuff for DX and usability of a withRouter component 👍
Rebased to add some code to docs and edit |
This looks great, @taurose :) thank you! |
This change is now causing a warning about prop types in react 15.5 as it uses React.PropTypes instead of the prop-types package. |
Thanks, I'll see about getting that fixed up shortly. We did merge in some stuff after the PropTypes fixes, so there are some inconsistencies to fix. |
This brings the current
withRouter
more in line with what we had in v3.withRouter
throws when no Router is present #4795). It's also what react-redux does.ref
to the original component. v3 and react-redux use a different API based onoptions: { withRef: true }
andgetWrappedInstance()
, but this way seems more comfortable to me to use with ref functions, and we don't need to change the signature to something likeoptions => Component => Component
or(Component, options) => Component
. It's also suggested in the react docs.