0

I am using react-boilerplate

, and I am building a small kind of project so that I can understand the use of selectors.

I watched this video which I enjoyed a lot and I believe I have a clear understanding of where I should use selectors.

So what the video says is that we should use selectors when we want to combine 2 or more states of redux and as a result have a combined state (always correct me if I am wrong please).

So given that definition, I have the following questions,

  1. While using the boilerplate should I use selectors even if I don't have to combine 2 or more states?

For example, I have written the following selector

const selectCardRendererDomain = () => (state) => state.get('cardRenderer');

export {
  selectCardRendererDomain,
};

Which doesn't make much sense if you ask me, but I like to keep things uniform in my projects so that I can easily follow the same flow every time I need to visit some old code.

  1. Are there any recipes that I can see how other, more experienced people are using selectors with the Boilerplate? I have already taken a look at the example of the boilerplate but I don't think that what I am looking for is there (again always correct me if I am wrong please).

Thanks in advance people

1 Answers1

1

Whether using a selector to access state properties or not, is a design decision and is up to you.

I personally prefer accessing state props through selectors only. The main benefits are:

  • decoupling state shape from your components
  • avoiding any pain if the state shape change in future
  • testability

Using selectors (or memoized selectors) to compute/derive data from the state - instead - is currently a best practice in Redux-based applications.

Redux DOCS have a page dedicated to Computing derived data. A very good read.

Andrea Carraro
  • 9,731
  • 5
  • 33
  • 57