Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to server-render redux app with async requests?

Tags:

reactjs

redux

I want to build server-rendered redux app with API request required to render route handler React components.

I'm passing request-making function in my actions and custom middleware fires requests and dispatches their results. For client it works just fine, but I'm struggling tow things at server-rendering:

  1. I need to know, which API requests are necessary for route rendering and don't want to duplicate that knowledge in both client and server-renderer code.
  2. On server I need to know then my API requests ended so I could render html to string and throw it to client.

Any ideas/links?

like image 379
Victor Suzdalev Avatar asked Nov 09 '22 02:11

Victor Suzdalev


1 Answers

I'm doing the same, basically using a function to get all the needed information from API calls, by specifying in your components which actions should run to fetch information.

I don't want to spend much time explaining that here, because there is an excellent tutorial of how to achieve this here (And it works perfect)

Cheers.

like image 159
Franco Risso Avatar answered Nov 14 '22 22:11

Franco Risso