Basic State

suggest change

State in React components is essential to manage and communicate data in your application. It is represented as a JavaScript object and has component-level scope, and it can be thought of as the private data of your component.

In the example below we define some initial state in the component’s constructor and use it in render.

class ExampleComponent extends React.Component {
  constructor(props){
    super(props);

    // Set up our initial state
    this.state = {
      greeting: 'Hiya Buddy!'
    };
  }

  render() {
    // We can access the greeting property through this.state
    return(
      <div>{this.state.greeting}</div>
    );
  }
}

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents