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

153
Views
Cómo htmlificar el texto de respuesta

Estoy recibiendo una respuesta en el texto de la siguiente manera

 <span class='text-4xl'>description1</span>

Y cuando lo imprimo en pantalla:

 import React,{useContext, useEffect} from 'react'; import blogsContext from '../context/blogsContext'; import { useParams } from 'react-router-dom'; export const Blog_read = (props) => { const context = useContext(blogsContext) const slug = useParams().slug const {read_blog,readblog} = context useEffect(()=>{read_blog(slug)},[readblog]) props.changetitle(readblog.title) const title = readblog.title const description = readblog.description return ( <> {title} {description} </> ); };

Luego imprime texto sin procesar como se muestra en imagen

Cómo renderizarlo en formato html

Gracias

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

0

Aquí hay una función para decodificar entidades HTML, espero que ayude:

 function htmlDecode(input) { var escaped = new DOMParser().parseFromString(input, "text/html"); return escaped.documentElement.textContent; }

EDITAR: Esto también funciona, pero puede correr el riesgo de XSS , asegúrese de que el HTML esté limpio antes de decodificar:

 function htmlDecode(input) { var escaped = document.createElement("textarea"); escaped.innerHTML = input; return escaped.value; }
about 4 years ago · Juan Pablo Isaza Report

0

Puede usar este paquete npm, html-to-react .

 import React,{useContext, useEffect} from 'react'; import { Parser } from "html-to-react"; import blogsContext from '../context/blogsContext'; import { useParams } from 'react-router-dom'; const HtmlToReactParser = new Parser(); export const Blog_read = (props) => { const context = useContext(blogsContext) const slug = useParams().slug const {read_blog,readblog} = context useEffect(()=>{read_blog(slug)},[readblog]) props.changetitle(readblog.title) const title = readblog.title const description = readblog.description return ( <> {title} {HtmlToReactParser.parse(description)} /* This will do the job */ </> ); };
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!