Skip to content

Instantly share code, notes, and snippets.

@rahulmore01
Created September 5, 2023 13:06
Show Gist options
  • Save rahulmore01/ce2c80a76c1e6246c60a773dee4e8ce9 to your computer and use it in GitHub Desktop.
Save rahulmore01/ce2c80a76c1e6246c60a773dee4e8ce9 to your computer and use it in GitHub Desktop.
blog- redux file userSlice.js
// userSlice.js
import { createSlice } from "@reduxjs/toolkit";
const initialState = {
userData: {},
loading: true,
error: null,
};
const userSlice = createSlice({
name: "user",
initialState,
reducers: {
setUserData: (state, action) => {
state.userData = action.payload;
state.loading = false;
state.error = null;
},
setLoading: (state, action) => {
state.loading = action.payload;
},
setError: (state, action) => {
state.loading = false;
state.error = action.payload;
},
},
});
export const { setUserData, setLoading, setError } = userSlice.actions;
export default userSlice.reducer;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment