0

行动

import { createAction } from '@ngrx/store';

export const logOut = createAction('[APP] LOGOUT');

减速机

import { createReducer, on } from '@ngrx/store';
import * as LogoutActions from '../actions';

export const clearStateReducer = createReducer(
  on(LogoutActions.logOut, state => {
    return (state = undefined);
  })
);

应用程序模块

StoreModule.forRoot(reducers, { metaReducers: [clearStateReducer] }),

我正在尝试在单击注销按钮时重置状态。我确实清除了本地存储,但我还需要清除 redux 状态。所以按照这个例子https://medium.com/@moneychaudhary/how-to-reset-the-state-or-clear-the-store-on-logout-in-ngrx-store-d2bd6304f8f3 但是我在元减速器上遇到错误,我需要一些帮助来解决这个问题。谢谢。我附上了错误截图

在此处输入图像描述

4

1 回答 1

4

creatReducer不是元减速器。

您将必须创建类似于以下内容的内容:

在此处输入图像描述

于 2019-10-12T07:22:34.850 回答