I'm reading the documentation for Redux and got stuck with reselect
. The code below creates a selector and the documentation says, if we want to use it in two VisibleTodoList
components then it won't work correctly.
import { createSelector } from 'reselect'
const getVisibilityFilter = (state, props) => state.todoLists[props.listId].visibilityFilter
const getTodos = (state, props) => state.todoLists[props.listId].todos
const getVisibleTodos = createSelector([getVisibilityFilter, getTodos], (visibilityFilter, todos) => {
switch (visibilityFilter) {
case 'SHOW_COMPLETED':
return todos.filter(todo => todo.completed)
case 'SHOW_ACTIVE':
return todos.filter(todo => !todo.completed)
default:
return todos
}
})
export default getVisibleTodos
Using the getVisibleTodos selector with multiple instances of the visibleTodoList container will not correctly memoize
const mapStateToProps = (state, props) => {
return {
// WARNING: THE FOLLOWING SELECTOR DOES NOT CORRECTLY MEMOIZE
todos: getVisibleTodos(state, props)
}
}
What does this mean? I can not figure out why it wouldn't work.