<div id="root">
    <!-- This element's contents will be replaced with your component. -->
</div>
function Component({myFunction}) {
  const refCount = React.useRef(0)
  const value = refCount.current ++
  
  return (
    <div>ComponentWithUseCallback, value = {value}</div>
  );
}

const ComponentWithUseCallback = React.memo(Component)

function ComponentWithoutUseCallback({myFunction}) {
  const refCount = React.useRef(0)
  const value = refCount.current ++
  
  return (
    <div>ComponentWithoutUseCallback, value = {value}</div>
  );
}

function App() {
  const [buttonState, setButtonState] = React.useState(false)
  const handleClickButton = () => {
    setButtonState(!buttonState)
  }
  const myFunction = React.useCallback(() => {
    return null
  }, [])
  
  return (
    <div>
      <button onClick={handleClickButton}>click</button>
      <ComponentWithUseCallback myFunction={myFunction}/>
      <ComponentWithoutUseCallback myFunction={myFunction}/>
    </div>
  )
}

ReactDOM.render(
  <App />, 
  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