Skip to content

Improve useDebounce callback type#2701

Open
itsmejay80 wants to merge 2 commits intostreamich:masterfrom
itsmejay80:fix-use-debounce-generic-fn
Open

Improve useDebounce callback type#2701
itsmejay80 wants to merge 2 commits intostreamich:masterfrom
itsmejay80:fix-use-debounce-generic-fn

Conversation

@itsmejay80
Copy link
Copy Markdown

@itsmejay80 itsmejay80 commented Apr 11, 2026

Fixes #2677

Description

Updates useDebounce to type the callback as a callable instead of the broad Function type. The callable is constrained to zero arguments because useDebounce schedules the callback through useTimeoutFn, which invokes it without forwarding arguments.

Runtime behavior and the existing [isReady, cancel] return type are unchanged.

Validation

  • yarn lint:types
  • yarn test tests/useDebounce.test.ts
  • yarn lint (passes with existing warnings)

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as before)

Checklist

  • Read the Contributing Guide
  • Perform a code self-review
  • Comment the code, particularly in hard-to-understand areas
  • Add documentation
  • Add hook's story at Storybook
  • Cover changes with tests
  • Ensure the test suite passes (yarn test)
  • Provide 100% tests coverage
  • Make sure code lints (yarn lint). Fix it with yarn lint:fix in case of failure.
  • Make sure types are fine (yarn lint:types).

Copilot AI review requested due to automatic review settings April 11, 2026 22:13
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR refines the TypeScript typing for useDebounce’s callback parameter, aiming to avoid the overly-broad Function type and document the updated signature.

Changes:

  • Updated useDebounce to accept a constrained callback type instead of Function.
  • Added a UseDebounceFn type alias for the callback.
  • Updated useDebounce documentation reference signature and parameter type description.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
src/useDebounce.ts Tightens the callback parameter typing for useDebounce.
docs/useDebounce.md Updates the reference section to reflect the new callback typing.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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.

Add Generic Fn for useDebounce

2 participants