【发布时间】:2020-06-06 09:31:38
【问题描述】:
所以我们可以在 reducer 中使用它:
const defaultState = {...};
export const userReducer = (state = defaultState, action: any) => {
// ...
}
有没有办法为每次调用 userReducer 获取一个 defaultState 对象? 像这样的:
const getDefaultState = () => ({...});
export const userReducer = (state = getDefaultState(), action: any) => {
// ...
}
这在 JS 中可能吗?它可能对 Redux reducer 没用,但总的来说我很好奇。
【问题讨论】:
-
在您的第二个示例中什么不起作用? this不是在做你想做的事吗?
-
我猜是的,我只是没想到它会起作用,但它是有道理的,谢谢
标签: javascript node.js ecmascript-2018