Skip to content
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

Merged
merged 3 commits into from
Apr 11, 2017
Merged

Improve withRouter #4838

merged 3 commits into from
Apr 11, 2017

Conversation

agundermann
Copy link
Contributor

@agundermann agundermann commented Mar 25, 2017

This brings the current withRouter more in line with what we had in v3.

  1. WrappedComponent: Lets people access the original component as a static property. Useful for unit testing the component without the router (might help with Rendering component wrapped in withRouter throws when no Router is present #4795). It's also what react-redux does.
  2. wrappedComponentRef prop: Passed as ref to the original component. v3 and react-redux use a different API based on options: { withRef: true } and getWrappedInstance(), but this way seems more comfortable to me to use with ref functions, and we don't need to change the signature to something like options => Component => Component or (Component, options) => Component. It's also suggested in the react docs.
  3. Hoist statics of the original component

@agundermann agundermann changed the title Update withRouter Improve withRouter Mar 26, 2017
Copy link
Member

@timdorr timdorr left a 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 👍

@agundermann
Copy link
Contributor Author

Rebased to add some code to docs and edit CHANGES.md

@mjackson
Copy link
Member

This looks great, @taurose :) thank you!

@mjackson mjackson merged commit 076a59f into remix-run:master Apr 11, 2017
@adamroyle
Copy link

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.

@timdorr
Copy link
Member

timdorr commented Apr 12, 2017

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.

@lock lock bot locked as resolved and limited conversation to collaborators Jan 18, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants