Skip to content

Instantly share code, notes, and snippets.

@adityatyagi
Created June 7, 2022 14:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adityatyagi/02719fa662a89042a74d68c557a59a77 to your computer and use it in GitHub Desktop.
Save adityatyagi/02719fa662a89042a74d68c557a59a77 to your computer and use it in GitHub Desktop.
// App.js (parent component)
...
...
...
// this function is NOT re-created on ever re-execution of this function
const onDemoClick = useCallback(() => {
console.log("Demo click function invoked");
}, []);
return (
<div>
<h2>Virtual DOM demo by Aditya Tyagi</h2>
{/* the function onDemoClick will not be re-recreated every-time on re-exection of this parent. It will only be re-created when any of the params passed to dependency array changes. */}
<DemoOutput onClick={onDemoClick} show={false} />
</div>
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment