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

202
Views
¿Cómo puedo representar una cadena en React JS que tiene componentes?

Tengo una cadena y quiero representarla en reaccionar JS

 const htmlString = "<h1> <Ref description=\"Magic may or may not be happening\"> hello magic</Ref></h1>" return ( <div> <h1> {htmlString}</h1> </div\>)

¿Puedo renderizar este htmlString en react js? ¡Por favor, ayuda!

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

0

Puede usar react-html-parser para lograr esto

 import React from 'react'; import ReactHtmlParser from 'react-html-parser'; class HtmlComponent extends React.Component { render() { const html = '<div>Example HTML string</div>'; return <div>{ ReactHtmlParser(html) }</div>; } }

Ver documentos aquí

about 4 years ago · Juan Pablo Isaza Report

0

Puede usar peligrosamente el atributo SetInnerHTML en un elemento html para establecer la cadena como HTML. Pero tenga en cuenta que configurar HTML como este en React es arriesgado, ya que puede exponer a sus usuarios a un ataque de secuencias de comandos entre sitios (XSS). Para saber más sobre cómo usarlo, consulte aquí los documentos oficiales de React: https://reactjs.org/docs/dom-elements.html#dangerouslysetinnerhtml

Publicar un ejemplo de caso de uso a continuación sobre cómo usarlo.

 function App() { function getMarkup() { return {__html: '<h3>My Content here..</h3>'}; // The HTML string you want to set } return ( <div className="App"> <div dangerouslySetInnerHTML={getMarkup()}></div> </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!