Skip to content

Decide the Callback hooks' argument shape and where the internal hooks live #590

Done

Description

@mnxmnz

#565 left two questions open, and #537 and the v0-to-v1 codemod (#543) depend on both.

Argument shape of the Callback hooks. On v1-base, useDebouncedCallback, useThrottledCallback, useInterval and useTimeout take one options object (#527, #530), while the Value and State hooks take (value, ms, options). @Antoliny0919 suggested (fn, ms, options) in #565.

Where the internal hooks live. #565 moved the debounce and throttle implementations to src/hooks/_internal to avoid a circular dependency. The earlier plan was to keep them in src/hooks/useDebounce and src/hooks/useThrottle and move them in v2.

Once decided, update the Direction in #533, C7 in hook-design-principles.md, the scope of #537 and the rules in #543.

Activity

  1. Antoliny0919 commented on Nov 12, 2026

    @Antoliny0919
    Contributor

    Thanks for opening this issue!

    For the first question, I think we should settle on one argument shape rather than support both. It seems to come down to whether we prioritize consistency across the Debounce/Throttle Callback, Value, and State hooks, or consistency with related hooks like useInterval and useTimeout.

    Changing the Value/State hooks to accept an object could make each argument’s meaning explicit through its name and provide consistency across a broader set of hooks. However, that would also expand the scope of this discussion to include changes to their interfaces.

    Personally, I’m leaning toward (fn, ms, options) for now. I see value, initialValue, the callback function, and the delay as core inputs that define what a hook does, while options like leading configure its behavior. This also makes me reconsider the current interfaces of useInterval and useTimeout.

    Putting the core inputs first and additional settings in a final options object makes that distinction clear at the call site. From an API consumer’s perspective, it also feels natural to pass the essential values first, followed by an object containing optional settings.

    Of course, an object based interface can also clearly express and enforce required inputs through types. Still, I don’t think consistency alone should mean every hook has to accept a single object. I’d rather prioritize how naturally each interface fits the hook’s functionality and how easy it is for users to provide its core inputs and additional settings.

    Regarding the internal hooks, I’d like to hear what others think and take some more time to consider their perspectives. Honestly, I’m not quite sure which approach would be best yet 😭

  2. mnxmnz commented on Nov 15, 2026

    @mnxmnz
    MemberAuthor

    Hi @Antoliny0919, thank you for thinking this through with us! 🙏 I agree with your point about looking at core inputs and options that change behavior separately. And I completely understand that you're not sure about the internal hooks yet.

    Here's where I'm leaning for now, and I'm open to other views. Please feel free to share yours!

    Argument shape

    I'm leaning toward keeping one options object for the Callback hooks.

    • Call-site readability. In useDebouncedCallback(setQuery, 300), it's hard to tell what 300 means without checking the signature, while { onChange: setQuery, debounceMs: 300 } reads on its own. This was also the reason we moved useInterval and useTimeout to one object in refactor(useInterval, useTimeout): take a single options object #530.
    • Consistency among hooks that take a function and a time. If the Callback hooks became positional, useInterval and useTimeout would stand apart, and we'd likely need to revisit refactor(useInterval, useTimeout): take a single options object #530 as well.
    • Other libraries name the time, too. ahooks takes useDebounceFn(fn, { wait }), and Mantine's useDebouncedCallback accepts (fn, { delay }).

    That said, moving from useDebounce to useDebouncedCallback becomes more than a rename. useDebounce stays available as a deprecated hook throughout v1, and I think the v0-to-v1 codemod (#543) could help with the migration as well.

    Internal hooks

    I think doing this in steps could work well.

    • In v1, the implementation stays in src/hooks/useDebounce and src/hooks/useThrottle, the derived hooks keep using it, and the two hooks are only marked as deprecated.
    • In v2, we stop exporting them and move them under _internal.

    Since #565 already moved them to _internal, v1-base now has two nearly identical copies. With this approach, the derived hooks would use src/hooks/useDebounce and src/hooks/useThrottle again, and the _internal copies would go away. That keeps one implementation in v1, and the move to _internal happens together with dropping the export in v2.

    I think this can still address #559. Since the implementation moves to _internal when the export is dropped in v2, I don't expect the derived hooks to block removing useDebounce and useThrottle.

    These are just my thoughts, so please let me know if I'm missing anything!

  3. Antoliny0919 commented on Nov 17, 2026

    @Antoliny0919
    Contributor

    Thank you for sharing your thoughts @mnxmnz 👍

    I think the examples you mentioned also have something in common with my suggestion. Both ahooks’s useDebounceFn(fn, { wait }) and Mantine’s useDebouncedCallback(fn, { delay }) name the time value while accepting the callback to be debounced as a separate argument.

    That was the distinction I was focusing on in my original suggestion. I felt that taking core inputs, such as the callback, as separate arguments and passing behavioral settings through an options object would naturally distinguish their roles at the call site.(Following my own reasoning, I should have included ms in the options object as well.)

    At the same time, I agree that a single object makes each value’s meaning explicit through its name. Considering that TanStack Query’s useQuery also includes core inputs like queryKey and queryFn in one object, I don’t think core inputs necessarily need to be positional arguments.

    Ultimately, I think both approaches are reasonable, and the choice comes down to which benefits we prioritize. Since we’re already moving toward a single options object for related hooks, I agree with maintaining that direction and consistency.

    Internal hooks

    If I understand correctly, the plan for v1 is to remove the implementations added under _internal and have derived hooks such as useDebouncedCallback use the existing useDebounce and useThrottle again. Then, in v2, we would remove the public exports and move the implementations to _internal.

    One thing I’m curious about: besides eliminating duplicate implementations, is there another reason to move away from the _internal structure already in place?

    If reducing duplication is the main goal, what about keeping the shared implementations in _internal and having both the existing public hooks and the derived hooks reference them? That would let us update the shared logic in one place while keeping the derived hooks independent of the deprecated public APIs.

  4. mnxmnz commented on Nov 18, 2026

    @mnxmnz
    MemberAuthor

    Thanks for the thoughtful reply, @Antoliny0919! 🙏

    Glad we're aligned on keeping one options object for the Callback hooks.

    For the internal hooks, removing the duplicate was my main reason, and your suggestion solves that too while keeping the derived hooks independent of the deprecated APIs. Let's keep _internal! Since the derived hooks already use it, the public useDebounce and useThrottle just need to use it as well before v1, and v2 only drops the exports.

    I'll update #533, #537, #543 and C7 to match. Thanks again! 🙌

  5. Antoliny0919 commented on Nov 18, 2026

    @Antoliny0919
    Contributor

    Sounds good @mnxmnz ! Would you like me to take care of the _internal changes? Happy to go with whatever works best for you!

  6. hyesungoh commented on Nov 18, 2026

    @hyesungoh
    Member

    @Antoliny0919 cool 👍 it would be great if you take care of this 🚀

  7. mnxmnz commented on Nov 29, 2026

    @mnxmnz
    MemberAuthor

    Both questions are settled: the Callback hooks keep one options object, and the shared debounce and throttle implementations stay in _internal (#613). #614 brings the Callback hooks in line. Thanks for the discussion!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions