0

I have got a problem with rerendering the component, when I switch to a different route and then back to my component. I am using React 0.14.3, react-router 1.0.2 and Immutable.js.

The reason is, that I compare props in my shouldComponentUpdate method.

shouldComponentUpdate(nextProps, nextState) {
    return !Immutable.is(nextProps.articles, this.props.articles);
}

If I change the route and go back, props.articles does not change, but I need to rerender the page anyways.

The question is, what do I need to consider in my shouldComponentUpdate method, to track, if the route has just changed?

Thanks in advance! Rico

Rico Herwig
  • 1,672
  • 14
  • 23
  • Haven't you tried? I suspect that you don't need to care about that since when you change the route your component will be re-mounted. – Grigory Katkov Dec 18 '15 at 16:18
  • My component is displaying a table of data. That data comes from an API and is stored in "articles". The route leading to that component is /articles. When I switch the the route / and then back to /articles, the component does not update, since the articles are the same as before. If I comment out my shouldComponentUpdate, it works. TL;DR - I tried, it did not work. – Rico Herwig Dec 18 '15 at 17:31
  • 1
    Well, your shouldComponentUpdate shouldn't even be called when you go back to the /articles. Because it isn't updating, it's mounting, componentDidMount is called. – Grigory Katkov Dec 18 '15 at 19:33
  • 1
    For instance, here are folks trying to solve the opposite problem - http://stackoverflow.com/questions/33431319/prevent-component-be-unmounted-with-react-router In other words, what you're trying to achieve is react router's default behavior. – Grigory Katkov Dec 18 '15 at 19:34

0 Answers0