Skip to content

Instantly share code, notes, and snippets.

@joboccara
Last active April 23, 2021 12:54
Show Gist options
  • Save joboccara/eb8af006c22f1c8ff5f7e976da902daa to your computer and use it in GitHub Desktop.
Save joboccara/eb8af006c22f1c8ff5f7e976da902daa to your computer and use it in GitHub Desktop.
const MemoComponent = React.memo(({ onClick }) => {
const buttonRef = React.useRef(null);
React.useEffect(() => {
const buttonDOM = buttonRef.current;
buttonDOM.addEventListener("click", onClick);
return () => buttonDOM.removeEventListener("click", onClick);
}, []);
return (
<Button ref={buttonRef}>Click on the memo</button>
);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment