Questions:
I'm trying to understand how to leverage immutability, and have a few questions:
-
The imperative code in
updateTodois the kind of stuff you can't guarantee people won't do, and is that the reason you have a very conservativeshouldComponentUpdateby default? You say never to mutatethis.statein the docs, but you assume that people are going to mutate objects within the app state? -
I'm having trouble figuring out how to write
shouldComponentUpdateeven if we updatethis.statefunctionally. Won'tnextPropsalways be new, sincerendercreates a new props object every time? How do we comparepropsandnextProps?
Answers:
-
You can't mutate. People do because javascript, for perf you must simply not mutate. It's recommended you use some kind of module for mutating stuff but having immutability under the hood like observ-array & observ-hash
-
nextPropsis always a fresh object, so dont compare it, compare the things that can change likedesc