Learn
To read a component’s state
, use the expression this.state.name-of-property
:
class TodayImFeeling extends React.Component { constructor(props) { super(props); this.state = { mood: 'decent' }; } render() { return ( <h1> I'm feeling {this.state.mood}! </h1> ); } }
The above component class reads a property in its state
from inside of its render
function.
Just like this.props
, you can use this.state
from any property defined inside of a component class’s body.
Instructions
1.
In App.js, get rid of the text inside of the <h1></h1>
.
Instead, in between the <h1></h1>
tags, read your state
‘s title
property.
2.
At the bottom of the file, render <App />
using ReactDOM.render()
.
See your component’s state
on display. Truly, you have the best of apps.
Take this course for free
By signing up for Codecademy, you agree to Codecademy's Terms of Service & Privacy Policy.