update redux

This commit is contained in:
Mac mini
2026-03-31 17:32:16 +07:00
parent 4f92253534
commit 1674632b0f
9 changed files with 226 additions and 24 deletions

View File

@@ -0,0 +1,29 @@
import { UserData } from '@/interface/user';
import { createSlice, PayloadAction } from '@reduxjs/toolkit';
interface UserState {
data: UserData | null;
isAuthenticated: boolean;
}
const initialState: UserState = {
data: null,
isAuthenticated: false,
};
const userSlice = createSlice({
name: 'user',
initialState,
reducers: {
setUserData: (state, action: PayloadAction<UserData>) => {
state.data = action.payload;
state.isAuthenticated = true;
},
clearUserData: (state) => {
state.data = null;
state.isAuthenticated = false;
},
},
});
export const { setUserData, clearUserData } = userSlice.actions;
export default userSlice.reducer;