Last active
January 2, 2024 09:47
-
-
Save ambroseus/c729dcf2e4f5853c27d0c1ee185e3704 to your computer and use it in GitHub Desktop.
Revisions
-
ambroseus revised this gist
Jan 2, 2024 . 1 changed file with 0 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,4 @@ // A Hook to define an event handler with an always-stable function identity function useEvent(handler) { const handlerRef = useRef(null); -
ambroseus revised this gist
Jan 2, 2024 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,4 @@ // A Hook to define an event handler with an always-stable function identity // https://github.com/reactjs/rfcs/blob/useevent/text/0000-useevent.md function useEvent(handler) { -
ambroseus renamed this gist
Jan 2, 2024 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
ambroseus created this gist
Jan 2, 2024 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,16 @@ // https://github.com/reactjs/rfcs/blob/useevent/text/0000-useevent.md function useEvent(handler) { const handlerRef = useRef(null); // In a real implementation, this would run before layout effects useLayoutEffect(() => { handlerRef.current = handler; }); return useCallback((...args) => { // In a real implementation, this would throw if called during render const fn = handlerRef.current; return fn(...args); }, []); }