有没有办法重新计算切片的初始状态。我正在尝试重置整个商店做:
const rootReducer = (state: any, action: any) => {
// Clear the state
if (action.type === clearState.type) {
// Clear all cached api requests
apiSlice.util.resetApiState();
// Return initial state
state = undefined;
}
return combinedReducer(state, action);
};
问题是我的auth切片具有以下初始状态:
export const initialState = {
isLoggedIn: checkIfUserIsAlreadyLoggedIn(),
email: "",
status: "idle",
errorMessage: "",
};
因此,当我启动应用程序并且checkIfUserIsAlreadyLoggedIn
返回true时,当我重置存储时,isLoggedIn
仍然为true。
有没有什么方法可以重新计算checkIfUserIsAlreadyLoggedIn
函数,从而重新计算初始身份验证切片状态?
谢谢!
否。这将是减速器的副作用,在Redux中这是严格禁止的。reducer应该只依赖于状态和操作,而不是外部数据源。
此外,CCD_5不会做任何事情,除非你发送它。
也许把它都写成一个砰的一声:
PD_4