Correctly. This is because Reselect only remembers the most recent set of inputs by default:
const a = someSelector(state, 1); // first call, not memoized
const b = someSelector(state, 1); // same inputs, memoized
const c = someSelector(state, 2); // different inputs, not memoized
const d = someSelector(state, 1); // different inputs from last time, not memoized
, , - .
, mapState
, ownProps
, , , memoize
const mapState = (state, ownProps) => {
const item = selectItemForThisComponent(state, ownProps.itemId);
return {item};
}
<SomeComponent itemId={1} />
<SomeComponent itemId={2} />
selectItemForThisComponent
(state, 1)
(state, 2)
back-to-back, .
"factory", connect
. mapState
, connect
mapState
. , :
const makeUniqueSelectorInstance = () => createSelector(
[selectItems, selectItemId],
(items, itemId) => items[itemId]
);
const makeMapState = (state) => {
const selectItemForThisComponent = makeUniqueSelectorInstance();
return function realMapState(state, ownProps) {
const item = selectItemForThisComponent(state, ownProps.itemId);
return {item};
}
}
export default connect(makeMapState)(SomeComponent);
1 2 selectItemForThisComponent
, , .
Redux: .