Created
September 5, 2023 13:06
-
-
Save rahulmore01/ce2c80a76c1e6246c60a773dee4e8ce9 to your computer and use it in GitHub Desktop.
blog- redux file userSlice.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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