我想从参数化选择器中创建一个选择器。我的理解是,只有在更新特定项目时才会发出此消息。
const getFeatureState = createFeatureSelector<FragmentsHierarchyState>(MY_FEATURE);
const getItem = createSelector(
getFeatureState,
(state: FeatureState, props: { itemId: string }) => {
return state.items[props.itemId];
}
);
const getItemValue = createSelector(
getItem, // <<< How to pass props here?
(state: ItemState) => return state.x + state + y
);
我不想执行以下操作,因为我不想每次功能状态更新时都发出新值:
const getItemValue = createSelector(
getFeatureState,
(state: FeatureState, props: { itemId: string }) => {
return state.items[props.itemId].x + state.items[props.itemId].y;
}
);
答案 0 :(得分:0)
getFeatureState
选择器也应该正常接收道具...
如果不是这种情况,可以使用工厂功能
const getItem = ({ itemId: string }) => createSelector(
getFeatureState,
(state: FeatureState) => {
return state.items[itemId];
}
);