Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

apply lastest ref pattern to useEventListener.ts #117

Merged
merged 2 commits into from
Feb 26, 2022
Merged

apply lastest ref pattern to useEventListener.ts #117

merged 2 commits into from
Feb 26, 2022

Conversation

TunA-Kai
Copy link
Contributor

With the old implementation, user have to use useCallback to store their handler if they don't want the event to be removed and re-added every time the component rerender. By saving the handler in the savedHandler we can remove handler in the dependency list of useEffect. Therefore user don't have to remember to memoize their function in the first place.

With the old implementation, user have to use `useCallback` to store their `handler` if they don't want the event to be removed and re-added every time the component rerender. By saving the `handler` in the `savedHandler` we can remove `handler` in the dependency list of `useEffect`. Therefore user don't have to remember to memoize their function in the first place.
@TunA-Kai TunA-Kai changed the title apply lastest ref pattern to store handler func apply lastest ref pattern to useEventListener.ts Feb 23, 2022
Copy link
Owner

@juliencrn juliencrn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's nice. Thank you, @TunA-Kai 👍

@juliencrn juliencrn merged commit f254a61 into juliencrn:master Feb 26, 2022
@TunA-Kai TunA-Kai deleted the patch-1 branch February 27, 2022 02:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants