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

149
Views
I want to load script after loading specific data from JSON in next js

I want to load Script tag after data.post.content is loaded inside HTML.

Basically, I want to run the MathJax.js script inside HTML.

My code:

return (
    <div>
      <h1>{data.post.title}</h1>
      <p dangerouslySetInnerHTML={{ __html: data.post.content }}></p>
      <Script type="text/javascript" src="https://www.hostmath.com/Math/MathJax.js?config=OK" strategy="afterInteractive"/>
    </div>
  );

My Script is working if I reload the page

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

The problem here is you're populating Script with client-side rendering (server-side rendering is good because data is loaded already on the server).

You can try this way to fix (below snippet), but with this way, you need to set data.post.content in states for UI re-rendering

return (
    <div>
      <h1>{data.post.title}</h1>
      <p dangerouslySetInnerHTML={{ __html: data.post.content }}></p>
      {data.post.content && <Script type="text/javascript" src="https://www.hostmath.com/Math/MathJax.js?config=OK" strategy="afterInteractive"/>}
    </div>
  );

about 4 years ago · Juan Pablo Isaza Report
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!