Let's create a component that has some initial state. You'll then render this component and update its state. This means that the component will be rendered twice. Let's take a look at the component:
import React, { Component } from 'react';
export default class MyComponent extends Component {
state = {
heading: 'React Awesomesauce (Busy)',
content: 'Loading...'
};
render() {
const { heading, content } = this.state;
return (
<main>
<h1>{heading}</h1>
<p>{content}</p>
</main>
);
}
}
The JSX of this component depends on two state values—heading and content. The component also sets the initial values of these two state values, which means that it can be rendered without any unexpected "gotchas." Now, let's look at some code that renders the component and then re-renders it by changing the state:
import React from &apos...