Quantcast
Channel: Active questions tagged javascript - Stack Overflow
Viewing all articles
Browse latest Browse all 138163

react-redux - in the hooks documentation, why is a parameter of the selector put in a separate parametric selector when calling createSelector()?

$
0
0

In the useSelector hook examples of react-redux documentation, there's a code snippet:

const selectNumOfTodosWithIsDoneValue = createSelector(
  state => state.todos,
  (_, isDone) => isDone,
  (todos, isDone) => todos.filter(todo => todo.isDone === isDone).length
)

As we can see, isDone is a parameter of selectNumOfTodosWithIsDoneValue. But why is it put in a separate parametric selector, i.e. (_, isDone) => isDone? Can I write it the following?

const selectNumOfTodosWithIsDoneValue = createSelector(
  (state, isDone) => state.todos.filter(todo => todo.isDone === isDone),
  filteredTodos => filteredTodos.length
)

What's the difference between the 2 approaches?


Viewing all articles
Browse latest Browse all 138163

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>