Home  >  Article  >  Web Front-end  >  How to render html tags in react

How to render html tags in react

王林
王林Original
2020-11-26 10:15:533967browse

React method of rendering html tags: You can use the dangerousSetInnerHTML attribute to render, such as [4819d21407d2f8483ea6e13bd490809f16b28748ea4df4d9c2150843fecfba68].

How to render html tags in react

The operating environment of this tutorial: windows10 system, react16 version. This method is suitable for all brands of computers.

(Learning video sharing: react video tutorial)

Method introduction:

If the string content of one end of the HTML tag is obtained from the backend ( textContent) needs to be rendered in the form of a tag, then we can use the dangerousSetInnerHTML attribute, but there will be a risk of xss attacks after using this attribute:

<div dangerousSetInnerHTML={{__html: textCotent}}></div>

Other methods recommended:

function createMarkup() {
  return {__html: &#39;First     Second&#39;};
}

function MyComponent() {
  return <div dangerouslySetInnerHTML={createMarkup()}></div>;
}

Related recommendations :js tutorial

The above is the detailed content of How to render html tags in react. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn