The "useEvent" hook is also a much needed api we need.

Christine Mathews

Christine Mathews / November 09, 2022

1 min read

What it does is to preserve a function identity over a re-render and also don't trigger a stale closure when a variable used inside the callback function changes.

It is much needed imo. useCallback does not work if one of the variable used inside the callback changes. We need to pass that variable to the dependency array of useCalkback and if we do so the hook becomes useless. New callback identity changes anyway every single time the variable changes.

useEvent will help use write much better React code. Just like the "use" hook will do.