By default, React escapes the HTML to prevent XSS (Cross-site scripting). If you really want to render HTML, you can use the dangerouslySetInnerHTML property:

<td dangerouslySetInnerHTML={{__html: this.state.actions}} />

React forces this intentionally-cumbersome syntax so that you don't accidentally render text as HTML and introduce XSS bugs.

Answer from Sophie Alpert on Stack Overflow
🌐
CodePen
codepen.io › Vpugh › pen › xEGywM
React Convert Plain Text to HTML
Minimize JavaScript Editor · Fold All · Unfold All · var Form = React.createClass ({ getInitialState: function(){ return { name: "Your Name", body: "Nice body content" }; }, render: function(){ return ( <div className="box"> <h1>React Convert from Input to HTML</h1> <p>H1 Content</p> <input type="text" value={this.state.name} onChange={this.handleChange} name="name" data-input-name="name" /> <h1 className="store">{this.state.name}</h1> <p>Body Content</p> <textarea value={this.state.body} onChange={this.handleChange} name="body" data-input-name="body"></textarea> <h2 className="textareaStore">{this.state.body}</h2> </div> ) }, handleChange: function(event){ // this.setState({[event.target.name]:event.target.value}) this.setState({[event.target.dataset.inputName]:event.target.value}) }, }); ReactDOM.render( <Form/>, document.getElementById('container') ); !
Discussions

want to convert text to react compnent
Only if you write your own custom parser from string to component composition. I had similar task on my previous project and we had to built it by ourselves More on reddit.com
🌐 r/react
5
0
April 15, 2024
javascript - Convert text to HTML - Stack Overflow
What I want to achieve Inside React I want to fetch an HTML page with fetch and from the response i get I want to extract some data from a div with a class called "myDiv" The data I am fetching ar... More on stackoverflow.com
🌐 stackoverflow.com
javascript - How to convert html string into plain text in React? - Stack Overflow
How do I convert html string (with a lot of tags etc.) into plain text in React? Any npm module maybe? I haven't found any methods for converting html string to plain text. I need this because I wa... More on stackoverflow.com
🌐 stackoverflow.com
javascript - React plain text to html code - Stack Overflow
I get a list of objects from the API. One of the values of each object is a plain string: snippet: "Chainsmokers were re-formed as an EDM DJ duo in 2012 under the management of More on stackoverflow.com
🌐 stackoverflow.com
🌐
DEV Community
dev.to › diwakarkashyap › convert-html-string-to-html-in-react-all-advance-methods-38hg
convert HTML string to HTML in React (all advance methods) - DEV Community
August 13, 2023 - If the HTML content has associated styles and you want to scope them to avoid conflicts, you can use libraries like styled-components or emotion to apply styles only to that chunk of content. ... You can render the content inside a shadow root which provides encapsulation for JavaScript, CSS, and templates. This can be done using React refs and direct DOM manipulation but is more involved.
🌐
npm
npmjs.com › package › html-react-parser
html-react-parser - npm
3 weeks ago - The parser converts an HTML string to one or more React elements.
      » npm install html-react-parser
    
Published   Apr 08, 2026
Version   6.0.1
🌐
Reddit
reddit.com › r/react › want to convert text to react compnent
r/react on Reddit: want to convert text to react compnent
April 15, 2024 -

So i have a text, i need to convert it into a react component and render it ,

const [jsxCode, setJsxCode] = useState(\
<mesh><boxGeometry args={[1, 1, 1]} /><meshBasicMaterial color="red" /></mesh>`);`

I tried different things

  1. using dangerouslySetInnerHTML inside the canvas, but that is not being allowed as only children or this is allowed

  2. tried using a parser library not working

  3. React.createElement(React.Fragment, {}, jsxCode);, this will have worked if jsxCode was not a string , but actual components

const [jsxCode, setJsxCode] = useState(
<mesh>
<boxGeometry args={[1, 1, 1]} />
<meshBasicMaterial color="red" />
</mesh>
);

Any pointers is deeply appreciated on conversion

🌐
npm
npmjs.com › package › html-converter-react
html-converter-react - npm
February 2, 2023 - **html-converter-react** is an isomorphic utility function that provides easy way to convert your string into a safely sanitized html. It's built on top of dompurify and it's made to work with react..
      » npm install html-converter-react
    
Published   Feb 02, 2023
Version   2.0.0
Author   Blagoj
🌐
Medium
medium.com › @diwakarkashyap › convert-html-string-to-html-in-react-all-advance-methods-8953590d8f39
convert HTML string to HTML in React (all advance methods | by Diwakar Kashyap | Medium
August 13, 2023 - If the HTML content has associated styles and you want to scope them to avoid conflicts, you can use libraries like styled-components or emotion to apply styles only to that chunk of content. ... You can render the content inside a shadow root which provides encapsulation for JavaScript, CSS, and templates. This can be done using React refs and direct DOM manipulation but is more involved.
Find elsewhere
🌐
DEV Community
dev.to › babynamenestlings_efe5ba9 › from-plain-text-to-web-magic-building-a-text-to-html-converter-with-javascript-and-react-25c7
From Plain Text to Web Magic: Building a Text-to-HTML Converter with JavaScript and React - DEV Community
March 21, 2025 - Building a text-to-HTML converter with JavaScript and React is a valuable skill for web developers. However, for quick and efficient conversions, Randzy's Text to HTML Converter offers a convenient solution.
🌐
npm
npmjs.com › package › react-html-parser
react-html-parser - npm
November 29, 2017 - Avoids the use of dangerouslySetInnerHTML and converts standard HTML elements, attributes and inline styles into their React equivalents.
      » npm install react-html-parser
    
Published   Nov 29, 2017
Version   2.0.2
Author   Peter Newnham
🌐
npm
npmjs.com › package › react-html-converter
react-html-converter - npm
Ships with integrations for node and browser.. Latest version: 0.3.2, last published: 8 years ago. Start using react-html-converter in your project by running `npm i react-html-converter`. There are 1 other projects in ...
      » npm install react-html-converter
    
Published   Mar 22, 2018
Version   0.3.2
🌐
DhiWise
dhiwise.com › post › react-html-parser-converting-html-strings-to-react-elements
Mastering React HTML Parser: A Comprehensive Tutorial
November 7, 2023 - React HTML parser works by parsing the HTML string into a tree of nodes, with each node representing an HTML element. The parser traverses the generated node tree, converting each node into a corresponding React element.
🌐
Reddit
reddit.com › r/reactjs › reframed - how to convert plain text to html code.
r/reactjs on Reddit: Reframed - How to convert plain text to html code.
May 28, 2022 -

I asked this question earlier but seems i didn't frame it properly. So here is the problem. There is some storage which stores html files with some content in it. The storage is done using an API which accepts html string, created a file and stores the html string as .html file.

Now my problem on React side is, there is an input box where user types the content which I want to convert to html code. When user types it, it is just plain text. What I want is a Library that course go through the text and place p, div, h1 etc tags in appropriate places so that I can then send this as html string to the API.

🌐
Medium
medium.com › @uigalaxy7 › how-to-render-html-in-react-7f3c73f5cafc
How to render HTML string in React | by UI Galaxy | Medium
December 18, 2019 - Sometimes you may want to render an HTML string when using React. This string may come from WYSIWYG editors. But there is a problem — JSX escapes all the HTML and thus all tags are visible to the user. Here we present 2 solutions to overcome the problem. In most cases, dangerouslySetInnerHTML should be enough. <div dangerouslySetInnerHTML={{__html: '<strong>strong text</strong>'}} />
🌐
SheCodes
shecodes.io › athena › 7844-converting-html-to-react-guide-examples
[React] - Converting HTML to React - Guide & Examples - | SheCodes
Find out how to convert HTML code to React components. We provide guide and example with basic steps and React syntax to create working react component.
🌐
Infyways
infyways.com › tools › html-to-jsx
Free Online HTML to JSX Converter for React | Infyways
Easily convert HTML to JSX using our free tool, designed for React developers. Quickly transform standard HTML code into React-compatible JSX for seamless integration.
🌐
Medium
medium.com › @andrewwil › convert-word-to-html-in-javascript-react-f19242508b4b
Convert Word to HTML in JavaScript (React app) | by Andrew Wilson | Medium
January 15, 2025 - Load the font file to ensure correct text rendering. Create a new document using the wasmModule.Document.Create() function. Load a Word (.doc or .docx) file using the LoadFromFile() function.