问题
I use redux in next js in my aplication:
//reducer
const initialState = {
carRequest: false,
carSuccess: false,
car: {},
error:''
};
export const carReducer = (state = initialState , { type, payload }) => {
switch (type) {
case HYDRATE: {
console.log(state, payload)
return {
...state,
...payload,
}
}
case CAR.GET_CAR_ERROR:
return {
...state,
carRequest: false,
carSuccess: false,
car: {},
error:payload
}
case CAR.GET_CAR_SUCCESS:
return {
...state,
carRequest: false,
carSuccess: true,
car: payload,
error:''
}
default:
return state;
}
};
When i dispatch it in the component:
export const getStaticProps = wrapper.getStaticProps(async ({ store }) => {
store.dispatch(getCarRequest('1'));
store.dispatch(END);
await store.sagaTask.toPromise();
});
I get:
{
carReducer:
car: {}
carReducer:
car: {id: .... my data, …}
carRequest: false
carSuccess: true
error: ""
// and below, also in this code i get all others reducers
}
Inside that object i also get the list of all my reduceres, and how you can see also i have carReducer
inside carReducer
. Why thi is happening and how to solve the issue?
来源:https://stackoverflow.com/questions/64675107/using-redux-with-next-js