For memoization/performance consideration, using useSelector with ShallowEqual
.
Will there be some more benefits for performance optimization using "Reselect/createSelector" option ?
Or both the options are same ?
Will have the data as JSON array objects at most of the selectors.
Before writing new selector , would like to consider performance/memoization benefits.
useSelector
will prevent re-render ofMyComponent
if theselectAndCompute
function computes the same result as last time it got triggered (and it gets triggered every time anything in redux state changes). But, this still requiresselectAndCompute
to run and compute some result. This computation in itself might be expensive.So, you can add
reselect
'screateSelector
to prevent even the computation done in theselectAndCompute
. For example ifselectAndCompute
depends only on the part of the statestate.transactions
you can define:Now, only if
state.transactions
has changed the expensive computation will run, otherwiseselectAndCompute
will immediately return the previous value. And finallyuseSelector
will then block the re-render, same as it would ifreselect
was not used.