1

In a React app, I need to call APIs server-side without server.js being aware of which APIs to call. The API calls should be encapsulated within the app's source code, and when server-side rendering is enabled, the APIs should be called internally prior to UI rendering.

I have tried the following:

  1. Using fetch in server.js and then rendering the app passing data. This is not a viable solution for my case.

  2. Using unsafe_componentWillMount(), which is the only lifecycle method that is supposed to be called on server rendering. I also tried using getDerivedState, but both call the API from the browser rather than on the server.

Mahesh
  • 513
  • 3
  • 12
Shal
  • 41
  • 2

0 Answers0