Questions:
I'm trying to understand how to leverage immutability, and have a few questions:
-
The imperative code in
updateTodo
is the kind of stuff you can't guarantee people won't do, and is that the reason you have a very conservativeshouldComponentUpdate
by default? You say never to mutatethis.state
in 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
shouldComponentUpdate
even if we updatethis.state
functionally. Won'tnextProps
always be new, sincerender
creates a new props object every time? How do we compareprops
andnextProps
?
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
-
nextProps
is always a fresh object, so dont compare it, compare the things that can change likedesc