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

[core] Use lintable pattern for debounced callbacks #27985

Merged
merged 1 commit into from
Aug 30, 2021

Conversation

eps1lon
Copy link
Member

@eps1lon eps1lon commented Aug 27, 2021

useCallback(debounce(fn)) is not lintable by exhaustive-deps (see facebook/react#20904).

However, we can make it lintable by just using useMemo:

-const handleSomething = useCallback(debounce(() => doSomething(someVariable)), [someVariable])
+const handleSomething = useMemo(() => debounce(() => doSomething(someVariable)), [someVariable])

Also: Please use global eslint-disable sparringly. There's rarely ever a reson to. Use eslint-disable-next-line instead. And if you do disable a rule, please add a rationale.

@eps1lon eps1lon added the core Infrastructure work going on behind the scenes label Aug 27, 2021
@eps1lon eps1lon requested a review from siriwatknp August 27, 2021 11:16
@mui-pr-bot
Copy link

mui-pr-bot commented Aug 27, 2021

No bundle size changes (experimental)

Generated by 🚫 dangerJS against e333a37

Copy link
Member

@siriwatknp siriwatknp left a comment

Choose a reason for hiding this comment

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

👍 Good to know.

@eps1lon eps1lon merged commit 1fe294b into mui:next Aug 30, 2021
@eps1lon eps1lon deleted the core/lintable-debounce branch August 30, 2021 05:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Infrastructure work going on behind the scenes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants