SamKirklandWA SamKirklandWA - 24 days ago 6
React JSX Question

React: text in state rendered as it is

I have a react code and I want to render state as

{this.state.text}
. It is rendered, but not as expected. Here's the state:

constructor(props) {
super(props);
this.state = {text: "<i>Hello, this is Introduction</i>"};
}


This is rendered as:

<i>Hello, this is Introduction</i>


Is there a way to render it as

Hello, this is Introduction

Answer

One of many ways to do it is to put text in state like this:

this.state = {text: "Hello, this is Introduction"};

and render the state's text using italic tag.like this

<i>{this.state.text}</i>