Awsome123 hmm, let me see…
// authSlice.ts
import { createSlice } from "@reduxjs/toolkit"
const initialState = {
auth: {
token: null as string | null,
isSignedIn: false,
name: "" as string,
phoneNumber: 0 as number,
email: "" as string,
role: "personal" as "personal" | "business"
}
}
const authSlice = createSlice({
name: "auth",
initialState,
reducers: {
signUp: (state, action) => {
const { name, email, phoneNumber, role } = action.payload;
state.auth.role = role;
state.auth.isSignedIn = true;
state.auth.name = name;
state.auth.phoneNumber = phoneNumber;
state.auth.email = email;
},
}
})
export const { signUp } = authSlice.actions;
export default authSlice.reducer;
here, I declare my initial state. think of initial state as the first variable in a usestate, so in the signup reducer I am setting those variables to a data.