As the name specifies, selectors are functions that are utilized to select a subset of data from a bigger collection of data. A selector holds two types of information, as follows:
- Information about where to find a particular subset of data
- Return the requested subset of data
Redux provides all state transformations and how these transformations mutate the store. However, it doesn't discuss a prescribed way for components to query the store. This is where the selector comes in. As mentioned, the Redux store stores a global store for an entire application to reduce the complexity and we need a mechanism for querying this store. The use of selectors is one of the possible solutions to this problem.
We can access the store through direct references, as follows:
const subsetOfState = store.someStateRoot.someProperty[key]
There are two issues with this approach, as follows:
- The application must know the actual shape of the store and whether the shape of the store...