<main></main>
<p class='debug'></p>
const $debug = $('.debug');
let renderCount = 0;
const Hello = React.memo((props) => {
$debug.text(`Renders: ${++renderCount}`);
return (<p>Hello {props.name}</p>);
});
class App extends React.Component {
constructor(props) {
super(props);
this.state = {ticks: 0};
this.tick = this.tick.bind(this);
}
tick() {
this.setState({ ticks: this.state.ticks + 1 });
}
render() {
return (
<div>
<Hello name="ynon" />
<Hello name={this.state.ticks} />
<button onClick={this.tick}>Tick</button>
</div>
)
}
}
ReactDOM.render(<App />, document.querySelector('main'));
View Compiled
This Pen doesn't use any external CSS resources.