Sunday, March 26, 2017

Updating Redux state doesn't trigger componentWillReceiveProps - solution


React Redux state is changed. However, the component which listens for state changes does not receive a call to componentWillReceiveProps().

Possible cause:

State should be an immutable object. Updates to it should be made by assigning new objects to its properties, not by modifying current properties like mutable objects. You might be passing the same object ( just modified) as the new updated state.

Make sure your state is updated by adding a new object, not just by a modification of an existing state object. If you pass the same old object ( by reference), redux won't detect it as a change. This was done to ensure that we use immutable objects for state.

More details here.

No comments:

Post a Comment

Ubuntu 12.04, 14.04, 16.04 - auto start an app or script before login

To run a command or application at startup, even before the user has logged in, you can use this file: /etc/rc.local The commands entered...