Previously, in the older way of using Redux, we could create a reducer like this - handling different action types but with the same action:
export default function authReducer(state = initialState, action) {
switch (action.type) {
case AUTH_ERROR:
case LOGIN_FAIL:
case LOGOUT_SUCCESS:
case REGISTER_FAIL:
localStorage.removeItem("xts0");
return {
...state,
token: null,
user: null,
isAuthenticated: false,
isLoading: false,
};
default:
return state;
}
}
Now, how can I achieve the same functionality using the createSlice
utility?
const authSlice = createSlice({
name: "auth",
initialState,
reducers: {
authError(state, action){},
loginFail(state, action){},
and so on
}
})