import { createRoot } from 'react-dom/client'
import React from 'react';
class Header extends React.Component {
constructor(props) {
super(props);
this.state = {favoritecolor: "red"};
}
shouldComponentUpdate() {
return false;
}
changeColor = () => {
this.setState({favoritecolor: "blue"});
}
render() {
return (
<div>
<h1>My Favorite Color is {this.state.favoritecolor}</h1>
<button type="button" onClick={this.changeColor}>Change color</button>
</div>
);
}
}
createRoot(document.getElementById('root')).render(
<Header />
);
/*
This example has a button that changes the favorite color to blue,
but since the shouldComponentUpdate() method is called,
the favorite color is still rendered as red
(because the method returns false).
*/