我正在尝试让Reselect记住我的带有动态参数的选择器
我的选择器:
import { createSelector, defaultMemoize } from 'reselect'
const allStatesSelector = store => store.state.states
export const getAllStates = createSelector(
allStatesSelector,
states => defaultMemoize(night => {
console.log('getAllStates called with night:', night)
const availableStates = night ? nightStates : dayStates
return states.filter(state => availableStates.includes(state.id))
}),
)
我这样称呼它:
states: getAllStates(store)(props.night)
选择器被调用1800次,而不是2次(考虑夜晚只能是对还是错)。
我想念什么?