I am currently using the server side rendering logic below (using reactjs + nodejs + redux) to sync the data for the first time and set it as the initial state in the repository.
fetchInitialData.js
export function fetchInitialData(q,callback){ const url='http://....' axios.get(url) .then((response)=>{ callback((response.data)); }).catch((error)=> { console.log(error) }) }
I retrieve the data asynchronously and load the output into the repository the first time the page is loaded with a callback.
handleRender(req, res){ fetchInitialData(q,apiResult => { const data=apiResult; const results ={data,fetched:true,fetching:false,queryValue:q} const store = configureStore(results, reduxRouterMiddleware); .... const html = renderToString(component); res.status(200); res.send(html); }) }
I have a requirement to make 4 to 5 API calls when the page loads, so you need to check if there is an easy way to achieve multiple calls when the page loads.
Do I need to bind api calls and manually combine the response from different API calls and send it back to load the initial state?
Update 1: I'm thinking of using the axios.all approach, can someone let me know if this is the perfect approach?
Learningner
source share