Skip to content

feat(useDebouncedState, useThrottledState): add new hook useDebouncedState and useThrottledState - #558

Merged
hyesungoh merged 10 commits into
toss:v1-basefrom
Antoliny0919:issue-538
Oct 14, 2026
Merged

hyesungoh merged 10 commits into
toss:v1-basefrom
Antoliny0919:issue-538

Conversation

@Antoliny0919

@Antoliny0919 Antoliny0919 commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

Overview

Closes: #538

Adds useDebouncedState and useThrottledState ⭐️🙌⭐️

Unlike the existing Callback and Value hooks, these hooks manage state internally and return the current value along with a debounced or throttled setter, respectively.
This lets callers control when state updates are applied without combining a separate useState hook.

Checklist

  • Did you write the test code?
  • Have you run yarn run fix to format and lint the code and docs?
  • Have you run yarn run test:coverage to make sure there is no uncovered line?
  • Did you write the JSDoc?

@changeset-bot

changeset-bot Bot commented Oct 11, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: ac107b9

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
react-simplikit Minor

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

@Antoliny0919
Antoliny0919 marked this pull request as draft October 11, 2026 09:55
@Antoliny0919 Antoliny0919 changed the title feat(useDebouncedState): add new hook useDebouncedState feat(useDebouncedState, useThrottledState): add new hook useDebouncedState and useThrottledState Oct 11, 2026
@codecov-commenter

codecov-commenter commented Oct 11, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (cf2626b) to head (ac107b9).

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff            @@
##           v1-base      #558   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           71        73    +2     
  Lines         2288      2346   +58     
  Branches       735       753   +18     
=========================================
+ Hits          2288      2346   +58     
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Comment thread packages/react-simplikit/src/hooks/useDebouncedState/useDebouncedState.ts Outdated
Comment thread packages/react-simplikit/src/hooks/useDebouncedState/useDebouncedState.ts Outdated
setDebouncedValue(() => value);
}

const debounced = useDebounce((next: T) => forwardChangedValue(next), debounceMs, { leading, trailing });

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Not for this PR, but useDebounce is going to be deprecated (#537), so I think our hooks should eventually stop depending on it. Opened #559 to track it 👀

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Right, I think the direction would be to clean up the reference based deduplication logic in State, Value, and Callback, and move the shared logic from useDebounce into useDebouncedCallback.

One behavioral difference between the two hooks is whether they skip calling the callback if the value is the same as the previously passed value when the debounce fires.

However, having State and Value use Callback could change the existing behavior around initial mounting, updater handling, and so on.
I think I’ll need to work through the implementation to figure out which references to remove and which logic to keep 🤔
(I can’t quite picture it all in my head just yet.)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

As mentioned in the issue, the simplest approach would be to keep it as an internal hook without trying to reuse the public hooks.

Comment thread packages/react-simplikit/src/hooks/useThrottledState/ko/useThrottledState.md Outdated
@Antoliny0919

Copy link
Copy Markdown
Contributor Author

I'll start working on this once that task is finished! 😎 -> #559

@hyesungoh hyesungoh left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thank you for your contribution! 👍

@hyesungoh
hyesungoh merged commit 71c1a07 into toss:v1-base Oct 14, 2026
19 checks passed
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.

3 participants