<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

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

  1. https://unpkg.com/react/umd/react.development.js
  2. https://unpkg.com/react-dom/umd/react-dom.development.js