So, I have stored a component in a variable const span = <span>{this.state.text}</span>. Now when I render this element and update the text within the state. The element is not re-rendered.
So this is my code
class App extends React.Component {
state = {
text: 'hey'
}
span = <span>{this.state.text}</span>
render() {
return (
<div>
{this.span}
<div>State: {this.state.text}</div>
<button onClick={()=>{this.setState({text: 'hello'})}}>Update</button>
</div>
)
}
}
So even after updating the state, the span has the initial value of the state. Is there any way to make this dynamic? I'm a newbie here.