You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This provides the view all the data it needs, but unfortunately organizations will always be a new array when store updates, resulting in redundant updates of the view even though nothing has changed.
This is especially noticed when you have a popup or modal that updates store as well, and the list in the background, resulting in slowness because the view is always updating.
Is this really the advised pattern? Should you modify shouldComponentUpdate to fit it for non-shallow comparison in this case? Perhaps you should pass down the functions to create the mapped items and do so in the render function instead?
The text was updated successfully, but these errors were encountered:
In this case, you can use reselect to create your selectors, so that their result can be memoized.
For example:
import{createSelector}from'reselect'constorganizationsSelector=state=>state.entities.organizations;constallOrganazationIdsSelector=createSelector(organizationsSelector,organizations=>organizations.byAll.ids)// with the same `organizations` & `allOrganazationIds`,// the selector always returns the same `allOrganazations`constallOrganazationsSelector=createSelector(organizationsSelector,allOrganazationIdsSelector,({ byId },ids)=>ids.map(id=>byId[id]))constmapStateToProps=state=>{const{ byAll }=organizationsSelector(state);constorganizations=allOrganazationsSelector(state);return{isFetching: byAll.isFetching,lastUpdated: byAll.lastUpdated,
organizations,};};
In all
real-world
examples (including code we use in our own work) I see the following pattern emerging inmapStateToProps
:This provides the view all the data it needs, but unfortunately
organizations
will always be a new array when store updates, resulting in redundant updates of the view even though nothing has changed.This is especially noticed when you have a popup or modal that updates store as well, and the list in the background, resulting in slowness because the view is always updating.
Is this really the advised pattern? Should you modify
shouldComponentUpdate
to fit it fornon-shallow
comparison in this case? Perhaps you should pass down the functions to create the mapped items and do so in the render function instead?The text was updated successfully, but these errors were encountered: