Skip to Content
Access a Component's state

To read a component’s state, use the expression

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.



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.


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.

Folder Icon

Take this course for free

Already have an account?