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;