Render Html

Asked

Viewed 60 times

0

I am consuming a json where I have a key with the value of an html tag:

import React, { useState, useEffect} from "react";
export const CardHome = () => {

  const [recebeDados, setRecebeDados] = useState([
    {
      jsonApi: {
        atrr: [
          {value:"<h1>Hello world</h1><p>Aqui eu renderizo um texto</p>"},
          {value:"<h1>Hello</h1><p>Aqui eu renderizo um texto SEGUNDO</p>"},
          {value:"<h1>Hello bRAZIL</h1><p>Aqui eu renderizo um TERCEIRO</p>"},
        ]
      }
    }
  ])

  return(
    <>
    {recebeDados.map((e,i) => (
      <ul key={i}>
        <li>{e.value}</li>
      </ul>
    ))}
    </>
  )
}

I would like to render the information without the HTML tags, will it be possible?

  • see if you can get help https://www.w3resource.com/javascript-exercises/javascript-string-exercise-35.php "strip_html" https://codepen.io/flourigh/pen/eYmjKW

  • Cannot do this without HTML.

1 answer

1

You can use the function replace().

Example: value.replace(/<[^>]*>/g, '');

Here he is deleting the symbols "<" and ">" and everything between them (replacing the symbols with nothing) using Regex (regular Expressions).

Browser other questions tagged

You are not signed in. Login or sign up in order to post.