I am using redux with react and typescript for my application. I am working with many items used at different places of my app. My state looks like this:
{
items: {42: {}, 53: {}, ... }, //A large dictionary of items
itemPage1: {
itemsId: [ 42, 34, 4 ],
...
},
itemPage2: { ...
},
...
}
The user can modify some attributes of the items dispatching some actions. When this happen I need to redraw the components that have been modified in each pages. The issue is that my items are quite big and I cant afford to redraw all of them at each small modification. I was wondering is this approach would work:
- I have a fist component
<ItemPage1>which connects to the store to get all of the states stored in the tree underitemPage1e.g. the list of items id:itemsId. - Inside
<ItemPage1>, I loop over theitemsIdproperty to generate multipleFilterItemcomponents:itemsId.map( itemId => return <FilterItem id=itemId>); Finally each
Itemis connected usingownPropsto get the correct part of the state:const mapStateToItemProps = (state, ownProps) => { return { item: state.items[ownProps.id], } } const mapDispatchToItemProps = (dispatch, ownProps) => { return null; } const FilterItem = connect( mapStateToItemProps, mapDispatchToItemProps )(Item)
Can you confirm or refute that if I update the item of id 42, then only this item is going to be re-rendered ?