2016-11-16 45 views
0

我有一個反應代碼,我想渲染狀態爲{this.state.text}。它被呈現,但不是如預期的那樣。這裏的狀態:反應:原樣呈現狀態的文本

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

這被渲染爲:

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

有沒有一種方法,以使其作爲

您好,這裏是簡介

回答

0

一個多種方式要做到這一點是把文字放在這樣的狀態:

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

,並使用斜體tag.like這

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

您可以使用dangerouslysetinnerhtml呈現狀態的文本:

<i dangerouslySetInnerHTML={{__html: this.state.text}} /> 

但它的使用更安全:

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