Permalink
Browse files

Add comment on deep cloning and re-rendering

  • Loading branch information...
markerikson committed Jan 12, 2018
1 parent 3ccc27c commit 4c9cbd15839d153e4aee9f935c11ec9ca4af10b3
Showing with 3 additions and 1 deletion.
  1. +3 −1 docs/faq/Performance.md
View
@@ -82,6 +82,8 @@ If you actually are concerned about reducer performance, you can use a utility s
Immutably updating state generally means making shallow copies, not deep copies. Shallow copies are much faster than deep copies, because fewer objects and fields have to be copied, and it effectively comes down to moving some pointers around.
In addition, deep cloning state creates new references for every field. Since the React-Redux `connect` function relies on reference comparisons to determine if data has changed, this means that UI components will be forced to re-render unnecessarily even though the other data hasn't meaningfully changed.
However, you *do* need to create a copied and updated object for each level of nesting that is affected. Although that shouldn't be particularly expensive, it's another good reason why you should keep your state normalized and shallow if possible.
> Common Redux misconception: you need to deeply clone the state. Reality: if something inside doesn't change, keep its reference the same!
@@ -158,4 +160,4 @@ Third, only cache a single copy of a record. This is especially important when r
**Discussions**
- [Stack Overflow: How to choose the Redux state shape for an app with list/detail views and pagination?](https://stackoverflow.com/questions/33940015/how-to-choose-the-redux-state-shape-for-an-app-with-list-detail-views-and-pagina)
- [Twitter: ...concerns over having "too much data in the state tree"...](https://twitter.com/acemarke/status/804071531844423683)
- [Advanced Redux entity normalization](https://medium.com/@dcousineau/advanced-redux-entity-normalization-f5f1fe2aefc5)
- [Advanced Redux entity normalization](https://medium.com/@dcousineau/advanced-redux-entity-normalization-f5f1fe2aefc5)

0 comments on commit 4c9cbd1

Please sign in to comment.