Hacker News new | past | comments | ask | show | jobs | submit login

To add a bit more context: React itself doesn't care about mutations in terms of re-rendering and virtual DOM diffing. In fact, it doesn't even care about mutations in terms of calling `setState()`. I'll recap a couple previous comments of mine at https://news.ycombinator.com/item?id=14706862.

You can mutate a component's state and then call `setState()`, and React will still update the component as you'd generally expect. For React, immutability primarily relates to implementing `shouldComponentUpdate` using the standard shallow equality comparison approach for the best performance, and general use of Functional Programming principles for avoiding side effects. For Redux, immutability matters for ensuring that reducer functions are pure with no side effects, as that is a requirement for time travel debugging and proper updates of Redux-connected components.

So, overall immutability is definitely an encouraged approach in the React/Redux ecosystem, and there's specific places where that immutability is important for desired behavior.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: