Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
import { createReducer, on } from '@ngrx/store';
import { setLoginStateSuccess, setErrorMessage } from '../login/login.action';
// ↑↑↑このactionを追加
export interface LoginModel {
isLogin: boolean;
errorMessage?: string;
}
export const initialState: LoginModel = { isLogin: false };
// ここから下が追加
export const loginReducer = createReducer(
initialState, // 最初に初期化する、ここから下がそれぞれの処理
on(setLoginStateSuccess, (state, { isLogin }) => { // setLoginStateSuccessアクションの処理、引数はisLogin
return ({...state, isLogin }); // 必ず最初は、...state。次にセットしたい情報(isLogin)
}),
on(setErrorMessage, (state, { errorMessage }) => { // ここもsetLoginStateSuccessアクションと同じ感じ
return ({ ...state, errorMessage });
}),
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment