Performance improvement strategies in Redux. Use memoized selectors to avoid redundant derivations in your mapStateToProps. Divide and flatten your reducers to prevent unnecessary re-renders of components.
4. mapStateToProps()
1. Runs when any part of the Redux store updates
2. Shallow compare of computed values (previous and new)
Shallow Compare
Render Do nothing
Not equal Equal
34. //reducer.js
const posts = (state, action) => {
switch(action.type) {
case "CHANGE_USER_NAME":
// find every post
// where the user as the author of the post
// or as the author of one of its comments
}
}
Updating Nested State
35. 1. Difficult to update
a. Duplicate data
b. Complex reducer logic due to nesting
2. Higher chance of redundant re-renders
Nested State
48. Normalized State
1. Easy to update
a. Single copy of data
b. Reducer logic more manageable (less nesting)
2. More connected & independent components -> less re-renders
49. Other Topics
● Multiple instances of memoized selectors
● Relationships and Tables (treating Redux like a relational DB)
● Normalizing nested data from API using Normalizr