Encountered an issue while using Redux Toolkit with Redux Persist. Unable to update the initial state of a user if it's null. The code consistently assigns null to the store regardless of passing parameters.
import { createSlice, PayloadAction } from "@reduxjs/toolkit";
import { IUser, Nullable } from "../../types";
const initialState = null as Nullable<IUser>
export const userSlice = createSlice({
name: 'user',
initialState: initialState,
reducers: {
set(state, action: PayloadAction<IUser>){
state = action.payload
}
}
})
export default userSlice.reducer;
However, when the initial state is structured as shown below, everything functions correctly. Curious as to why this is the case.
const initialState = {
user: null as Nullable<IUser>
}