Using State

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

App.jsx

import React from ‘react’;

class App extends React.Component {

constructor(props) {

super(props);

this.state = {

header: “Header from state…”,

content: “Content from state…”

}

}

render() {

return (

<div>

<h1>{this.state.header}</h1>

<h2>{this.state.content}</h2>

</div>

);

}

}

export default App;

main.js

import React from ‘react’;

import ReactDOM from ‘react-dom’;

import App from ‘./App.jsx’;

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

React State Basics
When to use state?

Get industry recognized certification – Contact us

keyboard_arrow_up
Open chat
Need help?
Hello 👋
Can we help you?