something is wrong when i try to use redux-toolkit #4722
Unanswered
Non00010110000
asked this question in
Help
Replies: 1 comment 2 replies
-
Somehow you're replacing the existing |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
userSlice.js:22 Uncaught (in promise) TypeError: Cannot create property 'error' on string 'User created successfully!' at signInFailure (userSlice.js:22:19) at @reduxjs_toolkit.js?v=69e8a274:1773:26
#reducers for make requests to api in mern app
import { createSlice } from "@reduxjs/toolkit";
const initialState = {
currentUser: null,
error: null,
loading: false,
};
const userSlice = createSlice({
name: "user",
initialState,
reducers: {
signInStart: (state) => {
state.loading = true;
},
signInSuccess: (state, action) => {
state.currentUser = action.payload;
state.loading = false;
state.error = null;
},
signInFailure: (state, action) => {
state.error = action.payload; // Handle both object and string payloads
state.loading = false;
},
});
export const {
signInStart,
signInSuccess,
signInFailure,
signOutUserStart,
} = userSlice.actions;
export default userSlice.reducer;
i try make the payload is string but it not solve the broblem !
signInFailure: (state, action) => {
state.error = typeof action.payload === 'string' ? action.payload : 'An error occurred';
state.loading = false;
Beta Was this translation helpful? Give feedback.
All reactions