React-redux store updates but React does not

Clarkiecuriouser提出了一个问题:React-redux store updates but React does not,或许与您遇到的问题类似。

回答者ChrisDan Abramov给出了该问题的处理方式:

The problem is in this piece of code:

        // clone the state
            var newState = Object.assign({}, state);

        // add the new transaction

        // update account balance
            newState.accounts[accountIndex].balance = action.payload.balance;

Cloning the state object doesn't mean you can mutate the objects it is referring to. I suggest you to read more about immutability because this isn't how it works.

This problem and solution to it are described in detail in Redux “Troubleshooting” docs so I suggest you to read them.

I also suggest you to take a look at Shopping Card example in Flux Comparison for Redux because it shows how to update nested objects without mutating them in a similar way to what you are asking.



下一篇:How to set default child view with Angular UI Router


欢迎 JavaScript 爱好者