-
-
Notifications
You must be signed in to change notification settings - Fork 10.6k
"withRouter" doesn't rerender elements when state is changed #4676
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
Comments
You are either using |
This is really confusing. I'm constantly hitting this issue and the workarounds seem to be ugly. I often have an intermediate component which implements Why the I also find the blocked-updates.md documentation weird because the proposed solution is to add |
It's impossible for me to make every pure component aware of the react-router so I made following workaround: class ListeningRoute extends React.Component {
componentWillMount() {
this.unlisten = this.props.history.listen(location => {
this.setState({location});
});
}
componentWillUnmount() {
this.unlisten();
}
render() {
return <Route {...this.props} location={this.state.location} />;
}
}
ListeningRoute = withRouter(ListeningRoute); This ListeningRoute component works exactly like the default This works because the Route component can get the location pathname from the UPDATE: Let's continue in #4671 |
Version
4.0.0-beta.8
Node: 6.6.9
Test Case
Ping me if you really want one. I can probably deploy something on heroku since this test depends on the browser url and I don't have access to it in jsbin.
Steps to reproduce
{ this.props.location.pathname }
in the html.Expected Behavior
I expect to see the component rerender on a history state change, but this doesn't seem to happen.
Actual Behavior
Component does not rerender. You can see this by adding a console.log in the render or using the jsx method described above.
Current Fix
This seems to work when rolling back react-router and react-router-dom to 4.0.0-beta.6. The withRouter then does have history context and works as intended. I'm not sure but it seems as if beta.8 introduced a bug.
The text was updated successfully, but these errors were encountered: