-
-
Save Rishit30G/f7a864ddca7e111f1a63fc56eb91f932 to your computer and use it in GitHub Desktop.
MessageSlice.tsx
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
| import {createSlice} from '@reduxjs/toolkit'; | |
| //! USER LIST->All,active/current ,loading,error ,setUser,setUsers | |
| //! USER MESSAGES (MESSAGE SLICE) | |
| const userlistSlice = createSlice({ | |
| name: 'userlist', | |
| initialState: { | |
| users: [], | |
| user: {}, | |
| currentUser: {}, | |
| active: false, | |
| loading: false, | |
| error: null, | |
| }, | |
| reducers: { | |
| setUsers: (state, action) => { | |
| state.users = action.payload; | |
| }, | |
| setUser: (state, action) => { | |
| state.user = action.payload; | |
| }, | |
| setCurrentUser: (state, action) => { | |
| state.currentUser = action.payload; | |
| }, | |
| setActive: (state, action) => { | |
| state.active = action.payload; | |
| }, | |
| setLoading: (state, action) => { | |
| state.loading = action.payload; | |
| }, | |
| setError: (state, action) => { | |
| state.error = action.payload; | |
| }, | |
| } | |
| }); | |
| const userMessagesSlice = createSlice({ | |
| name: 'userMessages', | |
| initialState: { | |
| messages: [], | |
| message: {}, | |
| loading: false, | |
| error: null, | |
| }, | |
| reducers: { | |
| setMessages: (state, action) => { | |
| state.messages = action.payload; | |
| }, | |
| setMessage: (state, action) => { | |
| state.message = action.payload; | |
| }, | |
| setLoading: (state, action) => { | |
| state.loading = action.payload; | |
| }, | |
| setError: (state, action) => { | |
| state.error = action.payload; | |
| }, | |
| }, | |
| }); | |
| export {userlistSlice, userMessagesSlice}; | |
| export const {setUsers, setUser, setCurrentUser, setActive, setLoading, setError} = userlistSlice.actions; | |
| export const {setMessages, setMessage} = userMessagesSlice.actions; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
LGTM ,the only thing want to add is to create separate files for each slice