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:
Using
fetch
inserver.js
and then rendering the app passing data. This is not a viable solution for my case.Using
unsafe_componentWillMount()
, which is the only lifecycle method that is supposed to be called on server rendering. I also tried usinggetDerivedState
, but both call the API from the browser rather than on the server.