Why does mobx-react observer break react-router-dom navlink active class?
http://stackoverflow.com/questions/43661560/why-does-mobx-react-observer-break-react-router-dom-navlink-active-class
I have same issues.
I am not react-router user, but I think this might relate to the fact that observer also automatically applies pure render mixin - see following.
Try to provide own shouldComponentUpdate implementation, it should take precendence over Mobx default behavior. See docs:
observer also prevents re-renderings when the props of the component have only shallowly changed, which makes a lot of sense if the data passed into the component is reactive. This behavior is similar to React PureRender mixin, except that state changes are still always processed. If a component provides its own shouldComponentUpdate, that one takes precedence
you can try use withRouter
Using the withRouter decorator before all mobx decorators fixes the issue for me.
Is there a more convenient way than wrapping each and every component in withRouter?
Just compose your decorators:
function observableWithRouter(component) {
return withRouter(observable(component))
}
Closing the issue as imho this is primarily an issue with RR, not with MobX (same issue arises when using RR with Redux), and there is a known solution to it. For more background on the issue see: https://medium.com/@mweststrate/how-to-safely-use-react-context-b7e343eff076
Thanks guys.
the same problem here, but with @withRoute decorator from 'react-router' package works perfectly. thanks, guys. I spent 3 days :sob:
For future reference, this is extensively described in the react router docs and will be addressed in the router package in the fuure: https://github.com/ReactTraining/react-router/blob/master/packages/react-router/docs/guides/blocked-updates.md