Provider component doesn't re-render

- 1 answer

Ad

I am not actually sure whether it's expected behaviour and I am just missing something :)

Container file:

https://gist.github.com/anonymous/2b93241de5573bd0a6bd

This Game component is used as follows:

https://gist.github.com/anonymous/80f0c2747c25a541e68d After pickColor action is dispatched, store is updated (I checked by subscribing to it from other place). So after this action is dispatched - Game component doesn't re-render.

And as I said, I am not sure if I didn't set up redux properly or is it just designed in that way so I have to re-render component manually by subscribing to store?

Ad

Answer

Ad

The react-redux bindings will only update your components when the state object is a new object instance.

Thus your reducers must return brand new objects. This is what immutability is all about.

BAD:

switch (action.type) {
    case SET_VALUE:
        state.value = action.value;
        return state;
}

GOOD:

switch (action.type) {
    case SET_VALUE:
        return Object.assign({}, state, {
            value: action.value
        });
}
Ad
source: stackoverflow.com
Ad