Using redux with next.js

こ雲淡風輕ζ 提交于 2021-01-29 14:00:35

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!