Defining State In A Simple Class Component
class MyComponent extends React.Component {
constructor(props) {
super(props);
this.state = {
loading: true
};
}
render() {
if (this.state.loading) {
return (
<p>Loading...</p>
);
} else {
// ...
}
}
}Last updated