Search⌘ K

Local Component State

Explore how to use local component state in React class components by initializing it in the constructor and managing it with setState. Understand how state drives rendering and how to safely modify it within your components.

We'll cover the following...

Local component state, also known as the internal component state, allows you to save, modify, and delete properties stored in your component. The ES6 class component then uses a constructor to initialize local component state. The constructor is called only once when the component initializes:

Let’s introduce a class constructor.

Javascript (babel-node)
class App extends Component {
constructor(props) {
super(props);
}
...
}

The App component is a subclass of Component, so the extends Component is in the App component declaration.

It is mandatory to call super(props);. It sets this.props ...