Open lindapaiste opened 2 years ago
I don't think there's going to be any harm in using Reselect here, if that's what you're asking. But also not sure if there's going to be much benefit either.
It’s going to be very slightly slower to use reselect unless you have non trivial selectors eg if the selector
In those cases reselect may offer an advantage.
I am writing a higher-order function as a helper for writing selectors on a Redux Toolkit slice and I'm wondering if it makes sense to use
reselect
here or not.Here is how that might look with and without using
createSelector
:Pros: In V2 the
subSelector
function would not get re-evaluated at all if there are changes to other slices but not tostate.mySlice
.Cons: There is maybe some overhead associated with the memoization and caching?
subSelector
here would be a simple selector that just accesses data from the state and does not transform it. I would then use the resulting selector as an input selector tocreateSelector
in other places.The goal is simply to save me from having to write
state: RootState
andstate.mySlice
everywhere when I am defining a whole bunch of selectors.I can write:
Instead of: