A
A
Andrey Okhotnikov2019-05-17 16:14:51
React
Andrey Okhotnikov, 2019-05-17 16:14:51

Loading data in Server side rendering?

I want to get data with SSR on Nextjs and save it to the redux state, through the getInitialProps dispatch action, it works, but the page comes to the browser without a state, how to forward the state from the server to the client?
Or is it impossible and props should be immediately substituted into the template?
What is the best way to work with getInitialProps in Nextjs

Index.getInitialProps = async ({ reduxStore }) => {
  reduxStore.dispatch(initialize());

  return { };
};

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
donnyho, 2019-07-07
@donnyho

Did you solve the issue?

S
Sergey Menshchikov, 2020-05-13
@theboss9976

Suddenly someone will come in handy - you need to wait for the result of the executiondispatch

Index.getInitialProps = async ({ reduxStore }) => {
  await reduxStore.dispatch(initialize());

  return { };
};

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question