DEV Community

Discussion on: 12 Things NOT To Do When Building React Apps With Redux

Collapse
 
fnky profile image
Christian Petersen • Edited

Not sure why they're called accessor functions, the common name for them is selectors. The benefit of using selectors is that you can make selecting slices of state a lot easier. They are also composable for cases where you want to use multiple selectors to select multiple slices of state and combine, transform or filter them (e.g. for relational data).

Another benefit is that selectors can be memoized. Since they are (and should be) pure functions they'll always produce the same output from the same input. For example, if you have a selector that does a lot of work (mapping, filtering, reducing, etc.) and it is called often, memoization can be useful to avoid performing the slow operations each time for the same inputs.

These practices and benefits doesn't only apply to selectors but also React components themselves!

I highly recommend reading about this within the reduxjs/reselect GitHub repository.