feat(core): add useDebouncedValue and useThrottledValue - #471
Conversation
🦋 Changeset detectedLatest commit: bebc20b 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 |
|
Size Change: +4.53 kB (+4.35%) Total Size: 109 kB 📦 View Changed
ℹ️ View Unchanged
|
There was a problem hiding this comment.
🟢 Approval recommended
The new hooks follow existing patterns, include SSR/StrictMode considerations, and add comprehensive automated test coverage and documentation for the new public APIs.
Pull request overview
Adds two new value-shaped hooks—useDebouncedValue and useThrottledValue—to complement the existing callback-shaped debounce/throttle hooks in react-simplikit. These hooks let callers keep owning state while consuming a delayed (debounced/throttled) copy for driving expensive renders or derived inputs.
Changes:
- Export new public APIs
useDebouncedValueanduseThrottledValuefrom the package root. - Implement both hooks with SSR-safe initialization, StrictMode-friendly effect behavior, and full option support (
leading/trailing). - Add comprehensive tests, hook docs (EN + KO), skill catalog entries, and a changeset.
File summaries
| File | Description |
|---|---|
| packages/react-simplikit/src/index.ts | Exports the two new hooks from the public entrypoint. |
| packages/react-simplikit/src/hooks/useDebouncedValue/useDebouncedValue.ts | Implements useDebouncedValue using useDebounce and a reference/settled guard. |
| packages/react-simplikit/src/hooks/useDebouncedValue/useDebouncedValue.spec.ts | Tests debounce timing, options, SSR safety, StrictMode behavior, and unmount cancelation. |
| packages/react-simplikit/src/hooks/useDebouncedValue/useDebouncedValue.md | Adds English API docs for useDebouncedValue. |
| packages/react-simplikit/src/hooks/useDebouncedValue/ko/useDebouncedValue.md | Adds Korean API docs for useDebouncedValue. |
| packages/react-simplikit/src/hooks/useDebouncedValue/index.ts | Re-export barrel for useDebouncedValue. |
| packages/react-simplikit/src/hooks/useThrottledValue/useThrottledValue.ts | Implements useThrottledValue using useThrottle and a reference/settled guard. |
| packages/react-simplikit/src/hooks/useThrottledValue/useThrottledValue.spec.ts | Tests throttle window behavior across leading/trailing options, SSR safety, StrictMode, and unmount cancelation. |
| packages/react-simplikit/src/hooks/useThrottledValue/useThrottledValue.md | Adds English API docs for useThrottledValue. |
| packages/react-simplikit/src/hooks/useThrottledValue/ko/useThrottledValue.md | Adds Korean API docs for useThrottledValue. |
| packages/react-simplikit/src/hooks/useThrottledValue/index.ts | Re-export barrel for useThrottledValue. |
| packages/plugin/skills/react-simplikit/SKILL.md | Adds both hooks to the skill catalog table. |
| packages/plugin/skills/react-simplikit/references/useDebouncedValue.md | Adds skill reference page for useDebouncedValue. |
| packages/plugin/skills/react-simplikit/references/useThrottledValue.md | Adds skill reference page for useThrottledValue. |
| .changeset/add-debounced-throttled-value.md | Declares a minor release for the new hook exports. |
Review details
- Files reviewed: 15/15 changed files
- Comments generated: 0
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #471 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 67 69 +2
Lines 2169 2227 +58
Branches 701 716 +15
=========================================
+ Hits 2169 2227 +58 🚀 New features to boost your workflow:
|
30e9676 to
d56eb97
Compare
…hrottle fires at the window boundary
d56eb97 to
bebc20b
Compare
Overview
Adds
useDebouncedValueanduseThrottledValue, the value-shaped counterparts to the existinguseDebouncedCallbackanduseThrottledCallback. The caller keeps owning the state; the hook returns a delayed copy of it.Interface
Both take
(value, wait, options?)withleading/trailingbooleans, matchinguseDebounce's option shape rather than theedgesarray thatuseThrottlestill uses. The existing hooks will be aligned to booleans in a later breaking change.leadingdefaulttrailingdefaultuseDebouncedValuefalsetrueuseThrottledValuetruetrueDesign notes
useDebouncedCallback/useThrottledCallback. A*Statevariant that owns the state is a separate question.leadingistrue. The effect skips when the incoming value is both unchanged and already settled, which also covers StrictMode's double-invoked effects.usePreservedReference.useDebouncedCallbackanduseThrottledCallback;_internal/currently holds only test utilities.Checklist
yarn run fixto format and lint the code and docs?yarn run test:coverageto make sure there is no uncovered line?