说我的商店有下面的嵌套CombineReducers
const rootReducer = () =>
combineReducers({
agent,
customer: customerReducer
});
const customerReducer = combineReducer({
profile,
account
})
在这种情况下,如果我想将完整的客户状态重置为其初始状态,怎么办?
注意:
"@reduxjs/toolkit": "^1.3.5",
"typescript": "^3.8.3"
答案 0 :(得分:1)
假设这是使用reduxjs/toolkit 配置您的商店的方式:
const store = configureStore({
reducer: rootReducer,
middleware: [
...getDefaultMiddleware(),
],
})
export default store
其中rootReducer
是:
const rootReducer = combineReducers({
agent: agentReducer,
customer: customerReducer
});
其中customerReducer
是嵌套的地方,即其他两个减速器的组合<< / em>:
const customerReducer = combineReducer({
profile,
account
})
要仅在Redux Store中{strong>重置状态,您需要创建一个 wrapper 减速器,将操作简单地委派给您的{{1} },并且只要该包装减速器收到customer
类型的操作,它都会重置客户状态:
customerReducer