当我使用metaReducer重置状态时,当我再次访问主页时,使用选择器显示给我的数据是重置之前的数据,有人知道如何解决吗?由于我尝试了许多不同的事情,结果是相同的
MetaReducer:
import { ActionReducer } from '@ngrx/store';
import { UserActionTypes } from '../../actions/actionTypes';
import { AppState } from '../../models/state';
export function clearStateReducer(reducer: ActionReducer<AppState>): ActionReducer<AppState> {
return (state, action) => {
if (action.type === UserActionTypes.Logout) {
state = undefined;
}
return reducer(state, action);
};
}
选择器:
import { AppState } from '../../models/state/app-state.model';
import { createSelector } from '@ngrx/store';
const getCurrentDate = (state: AppState) => state.date.currentDate;
export const getCurrentDateSelector = createSelector(
getCurrentDate,
(currentDate: Date) => currentDate
);
例如,当我再次登录时,它应该显示当前日期,而不是我以前在日期选择器中选择并保存在商店中的日期,因为完成重置后,该日期是当前日期。