feat(useDebouncedCallback,useThrottledCallback): accept any value type - #446
Merged
Conversation
Contributor
|
Size Change: +892 B (+0.93%) Total Size: 97.2 kB 📦 View Changed
ℹ️ View Unchanged
|
hyesungoh
force-pushed
the
docs/boolean-callback-examples
branch
from
August 27, 2026 16:30
c2866ee to
4272498
Compare
🦋 Changeset detectedLatest commit: 5841b8d The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
4 tasks
hyesungoh
marked this pull request as ready for review
August 27, 2026 16:31
Co-authored-by: wo-o29 <woogur29@gmail.com>
hyesungoh
force-pushed
the
docs/boolean-callback-examples
branch
from
August 27, 2026 16:40
4272498 to
5841b8d
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #446 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 58 58
Lines 1652 1664 +12
Branches 499 500 +1
=========================================
+ Hits 1652 1664 +12 🚀 New features to boost your workflow:
|
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 characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
useDebouncedCallbackanduseThrottledCallbackwere typed to accept only a boolean (onChange: (newValue: boolean) => void), while their own examples passed a string and a number. Nothing in the implementation depends on the value being a boolean — the hooks debounce or throttle a setter and skip a value equal to the last one forwarded — so the type is now generic:onChange: (newValue: T) => void.T, inferred fromonChange. Boolean callers are unchanged.useDebouncedCallbackno longer drops a first call offalse. It seeded its "last forwarded value" withfalse, so the very firstfalselooked redundant; it now starts from a sentinel, as fix(useThrottledCallback): invoke the callback when the first value is false #404 did foruseThrottledCallback. Afalsethat arrives while an initialtrueis still pending now replaces it — the settled value wins, which is what a debounced setter is expected to do.useImpressionRef(the internal consumer) relied on that swallowedfalseto avoid emittingonImpressionEndfor an element that was never impressed. It now tracks whether an impression started and only emits an end after a start.useDebouncedCallback, a number throughuseThrottledCallback, and the first-falsecase. The existing debounce test that encoded the old seed behaviour is updated.useThrottledCallbackdescribed a signature the hook never had (useThrottledCallback(fn, 300)) and is rewritten.This continues #267 by @wo-o29, which proposed the same generic type for
useDebouncedCallback. That branch predates thepackages/core→packages/react-simplikitmove and could not be rebased, so the change is re-applied here with the sentinel from #404 instead of anullseed and extended touseThrottledCallback. Credited as co-author on the commit.