Get data from API with Redux, NextJS and SSR

Viewed 313

I am using next-redux-wrapper, and i can get data to server store, but i cant send it to client store. My code looks like this:

In /pages/index:

export const getServerSideProps = wrapper.getServerSideProps(async (ctx) => {
  ctx.store.dispatch(testFunc(ctx));
  return {props: {data: ctx.store.getState().test.data}}
})

In store/../action:

export const testFunc = (ctx) => (dispatch) => {
  return fetch(url)
    .then(r => r.json())
    .then(r => {
      const data = r;
      dispatch({type: actionTypes.DATA, data});
    })
}

How can i do it right?

0 Answers
Related