Created
April 18, 2021 19:15
-
-
Save AllGistsEqual/b06cdec6c22353cf40dc65bb9ec6a0a0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// File: src/redux/ducks/user.ts | |
/* eslint-disable no-param-reassign */ | |
import { createAction, createReducer } from '@reduxjs/toolkit' | |
import { RootState } from '../index' | |
type UserState = { | |
login: boolean | |
} | |
const initialState: UserState = { | |
login: false, | |
} | |
export const setLogin = createAction('[USER] Set Login', (isLoggedIn: boolean) => ({ | |
payload: { | |
isLoggedIn, | |
}, | |
})) | |
export const selectLogin = (state: RootState): boolean => state.user.login | |
const userReducer = createReducer(initialState, builder => { | |
builder.addCase(setLogin, (state, action) => { | |
state.login = action.payload.isLoggedIn | |
}) | |
}) | |
export default userReducer |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment