Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

259
Views
React server side rendering - can't pass data from server handler file to react component

the below code snippet is for server handler function. build/index.html is from build folder generated by "react-scripts build" command

let finalData;

const app = ReactDOMServer.renderToString(
<StaticRouter location = {event.path} context = {{}}>
  <SSRApp />
</StaticRouter>);

let html = await fs.promises.readFile('build/index.html', 'utf8');

if(!html)
{
    finalData = {
      statusCode: 500,
      headers: { "Content-Type": "text/html" },
      body: "Oops, better luck next time!",
    };
}
else{

  const ssrData= {"message":"From Server"}

  html.replace('</head>', `<script>var ssrData= ${JSON.stringify(ssrData)}</script>`).replace('<div id="root"></div>', `<div id="root">${app}</div>`);
     
  finalData= {
      statusCode: 200,
      headers: { "Content-Type": "text/html" },
      body: html,
    };
    
}

Here i am trying to pass ssrData inside html string. In local node server ,it can able to pass and retrieve in client side using window object i.e window.ssrData. But in lambda , logs shows replaced string of div root element only not for ssrData.

Any suggestion on this?

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!