'Redux-toolkit multiple AsyncThunk at one slice
What is the best approach to manage multiple AsyncThunk at single slice. Would be correct if I put computed properties of each async action?
export const register = createAsyncThunk('user/register', async (payload, { rejectWithValue }) => {
})
export const login = createAsyncThunk('user/login', async (payload, { rejectWithValue }) => {
})
export const userSlice = createSlice({
name: "user",
initialState: { currentUser: "", },
extraReducers: {
[register.pending]: (state) => {
},
[register.fulfilled]: (state) => {
},
[register.rejected]: (state) => {
},
[login.pending]: (state) => {
},
[login.fulfilled]: (state) => {
},
[login.rejected]: (state) => {
},
}
});
Solution 1:[1]
Not sure if this is the answer you are looking for but it appears correct based on documentation: https://redux-toolkit.js.org/api/createreducer#usage-with-the-map-object-notation
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Elliot Young |