ReactJS - State

State is the place where the data comes from. We should always try to make our state as simple as possible and minimize the number of stateful components. If we have, for example, ten components that need data from the state, we should create one container component that will keep the state for all of them.

Using State

The following sample code shows how to create a stateful component using EcmaScript2016 syntax.


import React from 'react';

class App extends React.Component {
   constructor(props) {
      this.state = {
         header: "Header from state...",
         content: "Content from state..."
   render() {
      return (
export default App;


import React from 'react';
import ReactDOM from 'react-dom';
import App from './App.jsx';

ReactDOM.render(<App />, document.getElementById('app'));

This will produce the following result.

React State Simple