you might write a selector function like the following, to retrieve a post by its id:
const getPost = (state, id) => state.posts[id];
Selectors are especially useful when you have to compute derived data, based on the given conditions, the first example in the first page which you've shared is a good example.
Once you realise that you can avoid a lot of unnecessary derived data computations, you can use a library like reselect which lets you write memoized selectors to tackle the above problem.
You can read the following answer to learn a bit more about reselect:
Selectors in Redux, are functions which pluck out, and return the part of the Redux state which you are interested in!
As a simple example; if you have a normalised redux state tree like this;
{ posts: { 12: { id: 12, content: ..., }, ... }, ... }you might write a selector function like the following, to retrieve a post by its
id:const getPost = (state, id) => state.posts[id];Selectors are especially useful when you have to compute derived data, based on the given conditions, the first example in the first page which you've shared is a good example.
Once you realise that you can avoid a lot of unnecessary derived data computations, you can use a library like
reselectwhich lets you write memoized selectors to tackle the above problem.You can read the following answer to learn a bit more about
reselect: