Writing a selector and using a selector and dispatching it in a component
In the previous section, we successfully implemented reducers that can mutate the values of our state. This means that our state contains valuable data that we can get from the Angular components; we can use selectors to do this.
Selectors are pure functions that allow us to retrieve slices of state; we can use several helper functions, such as createSelector()
and createFeatureSelector()
, to create our selectors for the store.
Selecting root states
While selecting the root states, we will be using a pure function to create our selector. Let’s look at an example of a selector selecting the list of blogs under the root state (AppState
):
// blogs.selectors.ts export const selectBlogs = (state: AppState) => state.blogs
In the preceding code example, we have only created a function that returns the blogs
slice; this is feasible when we select slices under the project’s root state....