我将 2 个 reducer 组合成 1 个,比如 one: {a, b, c}, two: {x, y, z}
到 1,但我想要 one
在结果中传播。像这样:
{
a,
b,
c,
two : {x, y, z}
}
我试过这个:
combineReduceres({...one, two})
但这会导致:
{ two : {x, y, z}}
有人对此有任何解决方案吗..
最佳答案
恐怕这是不可能的。至少使用提供的 API。
如 docs 中所述:
The state produced by
combineReducers()
namespaces the states of each reducer under their keys as passed tocombineReducers()
.
但您可以通过编写自定义组合器来实现此功能。
这是一个工作沙箱:
注意:此代码是 redux 代码库中可用代码的简化版本。排除了一些验证部分以使代码更简单。您可以找到完整的 combineReducers
代码 here .
关于javascript - 在 Redux 的 combineReducers 中传播一个 reducer 结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53457875/