<div id="root">
<!-- This element's contents will be replaced with your component. -->
</div>
function ExpensiveComponent () {
const count = React.useRef(0)
return <div>Rerender ExpensiveComponent {count.current++}</div>
}
const MemorizedExpensiveComponent = React.memo(ExpensiveComponent)
function Component () {
const [msg, setMsg] = React.useState('')
return <div>
<input onInput={e => setMsg(e.target.value)} />
<br />
msg: {msg}
<br />
<br />
unused React.memo:
<ExpensiveComponent />
<br />
used React.memo:
<MemorizedExpensiveComponent />
</div>
}
ReactDOM.render(
<Component />,
document.getElementById('root')
);
View Compiled
This Pen doesn't use any external CSS resources.