javascript - Change content of Text element React -


this seems basic can't figure out it, , doesn't seem documented anywhere. i've got text element in react page

<text ref="warningtext"                   style={loginstyle.warninglabel}>{this.warningtext}</text> 

and want change content of text element. changing this.warningtext doesn't nor calling this.refs.warningtext.setnativeprops({text: text}); or changing other propname come with.

any great, thanks.

better use state instead of refs or else. that's reacts design pattern.

<text style={loginstyle.warninglabel}>{this.state.warningtext}</text> 

and in event can change text chnaging state , react automatically updates text.

this.setstate({warningtext: "some text"}) 

here's more documentation on setstate. gives of ins , outs of how use , not use state in components.


Comments