Reputation: 15
This is the authReducer i have
function signinReducer(state={userInfo:[]},action){
switch(action.type){
case USER_SIGNIN_REQ:
return {loading:true};
case USER_SIGNIN_SUCC:
return {loading:false,userInfo:action.payload}
case USER_SIGNIN_FAIL:
return {loading:false,error:action.payload}
default:
return{state};
}
}
the initialState of the store
const initialState={};
all the reducers
const reducer = combineReducers({
productReducer,
productDetailRed,
cartReducer,
authReducer
})
Why are multiple nested state been added to my authReducer, it starts with just 1 state and with every time i move to a different component a new nested state gets added. Pls help
Upvotes: 0
Views: 69
Reputation: 1342
You should return state instead of { state } in default case :
function signinReducer(state={userInfo:[]},action){
switch(action.type){
case USER_SIGNIN_REQ:
return {loading:true};
case USER_SIGNIN_SUCC:
return {loading:false,userInfo:action.payload}
case USER_SIGNIN_FAIL:
return {loading:false,error:action.payload}
default:
return state;
}
}
Upvotes: 2