I want to create a memoized selector which will update automatically when the state in the redux store changes.
I read about Reselect's createSelector
here:
https://redux.js.org/recipes/computing-derived-data
I see that mapStateToProps is being used to connect the selector to the store.. I'm currently using redux with hooks only (useDispatch
and useSelector
) without using connect(mapStateToProps, mapDispatchToProps)
.
Is there a way to use createSelector
but still without using connect
? If not, is there maybe another way to create a memoized selector?
Yes, they are nearly equivalent. useSelector
takes a pure function that when invoked is passed the entire redux store (i.e. state). Unlike Reselect's selectors however, they do not have the ability to receive passed props (other than through closure or currying). Save for a few edge cases most of your standard Reselect state selectors can be used with react-redux's useSelector hook.
Reselect selectors are memoizing selectors, so here is the section for working with them.
useSelector redux docs
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With