sajad torkamani

In a nutshell

A selector is a like a query into your state. It is a function that accepts the Redux store or a slice of the store and returns data based on that store.

This is what it looks like:

function TodoList() {
  // This anonymous arrow function is a selector!
  const todos = useSelector(state => state.todos)
}

Benefits

  • Encapsulate logic for looking up values (e.g., completed todo items, number of items completed).
  • Reuse same selection logic.
  • Memoize the selectors so that expensive computations aren’t re-calculated.

Sources

Tagged: Redux

Leave a comment

Your email address will not be published. Required fields are marked *