if I’m not mistaken, when you are not accessing the components props, then the selector you were already using in your
connect() will work just find in the
Of course, the selector function is not memoized by default, but that should not pose an issue if you were using a simple function that was not created through a selector function factory (i.e.
makeMapStateToProps ). So, as long as you are using the same function that selects the state pieces and you are not accessing the props of the component within it, you can safely re-use it.
Outside the context of this article, selectors are good both for abstraction and performance. Abstraction because you abstract away the “how this data is computed” and performance because you can use
reselect and other memoization libraries to make sure that you get referentially the same data regardless the amount of re-renders (supposing that the data is actually the same if you did a shallow comparison).Using
useMemo forces you to get away from doing things the “redux way” and you are just treating the store state as a simple object :P
Please feel free to correct me if I’m wrong in any of the points above, since I might have misunderstood something. If that’s the case please elaborate some more so I can fully get what you mean.
Thanks in advance man (and also thank you for the nice words :))