export const mySelector = createSelector(
[selectorA, selectorB], // but I want selectorB or selectorC to be chosen here using logic
(foo, bar) => {
// ...
}
);
我想在基于商店中的状态(即另一个选择器返回的值)创建此选择器时有条件地使用 selectorB
或 selectorC
。
我该怎么做?
最佳答案
只是要指出,接受的答案中建议的方法将在每个 selectorCorB 调用中评估 selectorB 和 selectorC 。这可能不是期望的行为。
一个实际的条件调用可能是这样实现的:
export const selectorCorB = createSelector(
selectorStateX
(...arguments) => arguments,
(x, arguments) => x ? selectorB(...arguments) : selectorC(...arguments)
);
关于javascript - 使用重新选择有条件地组成选择器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47096270/