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

312
Views
How to enter formatted template in React

I have an online letter template that I want to display ask text in my reactApp

My email is formatted with paragraphs and bold headings. How can I integrate the same formatting into React without having to use bruteforce and including a lot of tags.

I tried using a template literal to preserve the formatting but it does not work.

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

0

As Joseph stated in the comments, you can use dangerouslySetInnerHTML to render a string of HTML.

Example: code-sandbox

export default function App() {
  const htmlString = "<h1>Hello world</h1>";
  return (
    <>
      <div dangerouslySetInnerHTML={{ __html: htmlString }}></div>
    </>
  );
}

However, it's important to be aware of the security risks as the documentation states:

dangerouslySetInnerHTML is React’s replacement for using innerHTML in the browser DOM. In general, setting HTML from code is risky because it’s easy to inadvertently expose your users to a cross-site scripting (XSS) attack. So, you can set HTML directly from React, but you have to type out dangerouslySetInnerHTML and pass an object with a __html key, to remind yourself that it’s dangerous.

Source: https://reactjs.org/docs/dom-elements.html#dangerouslysetinnerhtml

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!