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

How to render html tags in react

王林
Release: 2020-11-30 11:43:36
Original
4098 people have browsed it

React method of rendering html tags: You can use the dangerousSetInnerHTML attribute to render, such as [<div dangerousSetInnerHTML={{__html: textCotent}}></div>].

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>
Copy after login

Other methods recommended:

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

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

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!

Related labels:
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template