I'm trying to implement @reduxjs/toolkit into my project and currently I'm facing problem with using spread operator
const initialState: AlertState = {
message: '',
open: false,
type: 'success',
};
const alertReducer = createSlice({
name: 'alert',
initialState,
reducers: {
setAlert(state, action: PayloadAction<Partial<AlertState>>) {
state = {
...state,
...action.payload,
};
},
},
});
When I'm assigning state to new object my store doesn't update. But if I change reducer to code
state.message = action.payload.message || state.message;
state.open = action.payload.open || state.open;
But that's not very handy. So is there way to use spread operator?