mirror of
https://github.com/morbalint/kemkas.git
synced 2026-07-18 03:13:46 +00:00
add redux and user slice
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
import { createSlice } from '@reduxjs/toolkit'
|
||||
|
||||
type LoadingState = "not-started" | "loading" | "finished"
|
||||
|
||||
export const userSlice = createSlice({
|
||||
name: 'user',
|
||||
initialState: {
|
||||
state: "not-started" as LoadingState,
|
||||
email: null,
|
||||
},
|
||||
reducers: {
|
||||
load: (state) => {
|
||||
state.state = "loading"
|
||||
},
|
||||
setUser: (state, action) => {
|
||||
state.state = "finished"
|
||||
state.email = action.payload
|
||||
},
|
||||
unsetUser: (state) => {
|
||||
state.state = "finished"
|
||||
state.email = null
|
||||
}
|
||||
},
|
||||
})
|
||||
|
||||
// Action creators are generated for each case reducer function
|
||||
export const { load, setUser, unsetUser } = userSlice.actions
|
||||
|
||||
export const userSelector = userSlice.selectSlice
|
||||
|
||||
export default userSlice.reducer
|
||||
Reference in New Issue
Block a user