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

[@mantine/hooks] use-throttled-*: Emit updates on trailing edges #6257

Merged
merged 1 commit into from
May 23, 2024

Conversation

dfaust
Copy link
Contributor

@dfaust dfaust commented May 19, 2024

Make sure the throttled value/state/callback always has the last value it was called with after the timeout has expired.

  • I refactored the hooks to all depend on a single hook (useThrottledCallbackWithClearTimeout) that contains the throttling logic. This hook is not exported.

  • Mantine doesn't use the react-hooks/exhaustive-deps lint. So there is no warning for the missing wait in the old use-throttled-value implementation. This is why I introduced the waitRef. I later saw that use-throttled-state and use-throttled-callback did include the wait dependency. So maybe it was just a mistake. But anyway I kept the waitRef for now.

  • I also adjusted the tests to reflect the new behavior and unified the "should clear timeout on unmount" tests.

Fixes: #6220

@dfaust dfaust force-pushed the throttled-hooks-trailing-edge branch from 4b32ef8 to 1920554 Compare May 19, 2024 19:37
@dfaust dfaust force-pushed the throttled-hooks-trailing-edge branch from 1920554 to c10025e Compare May 20, 2024 08:27
@rtivital rtivital merged commit 92e9036 into mantinedev:master May 23, 2024
1 check passed
@rtivital
Copy link
Member

Thanks!

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.

use-throttled-value does not always issue an update with the last value
2 participants