Repository navigation
Description
Hooks that do similar things on v1-base take their arguments in different shapes, so knowing one hook doesn't tell you how to call its sibling. #590 settled on one options object for the Callback hooks. This issue is about lining up the rest before 1.0.0. Every hook that changes also goes into the v0-to-v1 codemod (#543).
What's not the problem
Positional arguments by themselves are fine.
const [isOpen, toggle] = useToggle(false); // one clear value
const debouncedQuery = useDebouncedValue(query, 300); // the shape the ecosystem uses
useAsyncEffect(async () => { await load(); }, [id]); // the same shape as useEffectWhat is the problem
1. Siblings look different. Hooks that take a function and a time take one object, while hooks that take a value and a time take positional arguments. Callbacks also go in the object for some hooks and in the first argument for others.
// a function and a time: one object
useDebouncedCallback({ callback: search, debounceMs: 300 }); // after #614
useInterval({ onTick: refresh, delayMs: 1000 });
// a value and a time: positional
useDebouncedValue(query, 300);
useDebouncedState('', 300);
// a callback in the object
useImpressionRef({ onImpressionStart: logImpression });
// a callback as the first argument
useLongPress(openMenu, { delayMs: 500 });
useIntersectionObserver(onIntersect, { threshold: 0.5 });2. Some hooks take two or more arguments, all positional. You can't tell what the second argument is without opening the signature, while useControlledState takes the same kind of equalityFn by name.
useInputState('', value => value.trimStart());
usePrevious(user, (a, b) => a.id === b.id);
usePreservedReference(rawFilters, isSameFilters);
useOutsideClickEffect(element, close);
useControlledState({ value, defaultValue: '', onChange, equalityFn: isSameFilters });Option 1: the shape follows what the hook takes
Keep the shapes the ecosystem already uses, and fix only the hooks that break them.
| The hook takes | Shape | Like |
|---|---|---|
| a value | the value first, the rest in a trailing options object | useState(0), useDebouncedValue(value, wait) |
| a callback | one options object | #590 |
| a callback and deps | (callback, deps) |
useEffect(callback, deps) |
6 hooks change. Each pair is today's call, then the new one.
useLongPress(openMenu, { delayMs: 500 });
useLongPress({ onLongPress: openMenu, delayMs: 500 });
usePageVisibilityEffect(onVisibilityChange);
usePageVisibilityEffect({ onChange: onVisibilityChange });
useIntersectionObserver(onIntersect, { threshold: 0.5 });
useIntersectionObserver({ onIntersect, threshold: 0.5 });
useInputState('', transformValue);
useInputState('', { transformValue });
usePrevious(user, isSameUser);
usePrevious(user, { equalityFn: isSameUser });
usePreservedReference(rawFilters, isSameFilters);
usePreservedReference(rawFilters, { equalityFn: isSameFilters });useOutsideClickEffect(element, close) stays as an exception, since useOutsideClickRef({ onOutsideClick }) from #616 is its object form.
- 👍 Short, familiar calls like
useToggle(false)anduseDebouncedValue(query, 300)stay as they are. - 👍 Only 6 breaking changes, so the codemod stays small.
- 👎 Value hooks and Callback hooks still look different (
useDebouncedValue(query, 300)next touseDebouncedCallback({ callback, debounceMs: 300 })). The rule explains the difference, but you need to know which kind a hook is before you call it. - 👎 C7 in
hook-design-principles.md("Object Parameters") needs to be rewritten.
Option 2: one options object for every hook that takes arguments
One rule: if a hook takes arguments, it takes one object. Hooks that take a callback and deps stay as they are, because react-hooks/exhaustive-deps can check a custom hook's deps through additionalHooks only when they are positional.
18 hooks change. Each pair is today's call, then the new one.
useToggle(false);
useToggle({ initialValue: false });
useBooleanState(false);
useBooleanState({ initialValue: false });
useList([1, 2]); // useMap and useSet too
useList({ initialValue: [1, 2] });
useCounter(1, { min: 1, max: 10 });
useCounter({ initialValue: 1, min: 1, max: 10 });
useInputState('', transformValue);
useInputState({ initialValue: '', transformValue });
useDebouncedValue(query, 300); // useThrottledValue too
useDebouncedValue({ value: query, debounceMs: 300 });
useDebouncedState('', 300); // useThrottledState too
useDebouncedState({ initialValue: '', debounceMs: 300 });
useStorageState('theme', { defaultValue: 'light' });
useStorageState({ key: 'theme', defaultValue: 'light' });
usePrevious(user, isSameUser);
usePrevious({ value: user, equalityFn: isSameUser });
usePreservedReference(rawFilters, isSameFilters);
usePreservedReference({ value: rawFilters, equalityFn: isSameFilters });
useLongPress(openMenu, { delayMs: 500 });
useLongPress({ onLongPress: openMenu, delayMs: 500 });
usePageVisibilityEffect(onVisibilityChange);
usePageVisibilityEffect({ onChange: onVisibilityChange });
useIntersectionObserver(onIntersect, { threshold: 0.5 });
useIntersectionObserver({ onIntersect, threshold: 0.5 });
useOutsideClickEffect(element, close);
useOutsideClickEffect({ container: element, onOutsideClick: close });- 👍 No gap between siblings: every hook with arguments looks the same, and it already matches C7.
- 👍 Every value is named where it's used, so a call reads on its own. Now that AI writes much of the code, that may help both sides: the AI doesn't have to remember argument order, and the person reviewing doesn't have to guess what a bare
300orfalsemeans. - 👎 Calls that were already clear get longer:
useToggle(false)becomesuseToggle({ initialValue: false }). - 👎 Value hooks no longer look like
useStateor other libraries. - 👎 18 breaking changes, and the codemod has to cover all of them.
What I'd like to hear
By my own reading, Option 1 fits: positional arguments aren't the problem, but sibling hooks that look different and hooks that take several positional arguments are. Still, now that AI writes most of the code, I wonder if Option 2, where every value is named, is easier for both people and AI to understand. Which one do you think fits react-simplikit better?
The callback key names are open too. #614 uses callback in useDebouncedCallback, while the others use on* (onTick, onLongPress), so the names above are placeholders.
Once we decide, we update the argument rule (C7) in hook-design-principles.md and the Direction in the v1 roadmap (#533), and add the changed hooks to the v0-to-v1 codemod (#543).
Activity
hyesungoh commentedon Nov 26, 2026
@Antoliny0919 I love to hear your thoughts on this when you have a moment.
Which option feels more natural to you, or is there something we're missing? 🤔 no rush 👍
Choi-Jung-Hyeon commentedon Nov 27, 2026
I'd go with Option 1. The 6 hooks it changes are the ones with a callback first or a second unnamed argument, which is what the issue calls the problem.
useToggle(false)anduseDebouncedValue(query, 300)already read fine, and the codemod stays small.One hook isn't in either list:
useConditionalEffect(effect, deps, condition)takes a third positional argument after deps. Under both options it's an exception to(callback, deps). Should it stay as is?On key names,
on*fits callbacks that run when something happens (onTick,onLongPress). InuseDebouncedCallbackthe function is what gets wrapped and returned, not an event, socallbackseems fine there.Antoliny0919 commentedon Nov 29, 2026
Thanks for asking for my thoughts @hyesungoh 🙌
I prefer Option 1, with a small adjustment.
My main concern isn't the number of breaking changes, although that matters too. It's that we would be converting hooks that are already clear to object parameters for the sake of consistency.
For example, hooks like
useBooleanState,useToggle, anduseListalready give us a good idea of what arguments to expect from their names. They're simple, and their meaning is intuitive. It's similar to a function named add: the name alone gives us a reasonable expectation of the arguments it takes.Object parameters offer several benefits -> explicit names, consistency, and independence from argument order, but I'm not sure that making argument names explicit adds much to these simple hooks. It might just make their call sites unnecessarily verbose.
I do see your point about AI. As we spend more time reviewing code than writing it, explicit argument names may become more valuable. I can't confidently assess the impact on AI itself, though. From a human review perspective, I still think a simple, familiar call is often easier to recognize and understand.
If a hook becomes complex enough that its arguments are no longer predictable, moving to an object can improve clarity. But when the interface is already clear, making it more explicit may add little while sacrificing simplicity. This matters even more for hooks that follow familiar ecosystem conventions.
useControlledStateis a good example of where object parameters provide meaningful clarity. When a hook accepts several callbacks or numeric values, named properties help distinguish each callback's role and make the meaning of otherwise unexplained numbers clearer.That said, I'm also a little uncomfortable with the different calling conventions within the debounce/throttle family.
So, while following Option 1 overall, I'd prefer to make the debounce/throttle hooks consistent by using object parameters across that family. My reasons are that this would align them with other time-related hooks, such as
useIntervalanduseTimeout, and that explicit parameter names are particularly helpful for clarifying the role and unit of time values.(In this case, I think consistent calling conventions across closely related hooks would be more valuable than preserving familiar ones. Especially since we provide separate hooks for closely related functionality.)hyesungoh commentedon Dec 1, 2026
thanks for the thoughts both 🙏
you're right, and my example in the issue was off. option 1 says "the value first, the rest in a trailing options object", so
300belongs in that object too 😅 applied as written, option 1 also changes these on top of the 6 in the issue:thanks @Choi-Jung-Hyeon for catching
useConditionalEffectand @Antoliny0919 for the unnamed time values 👍 with these, every time value has a name and the rule has no exception.that said, I'm still torn about option 2 🤔 I feel like we're in a world where code that's clear for people to read is just better. I think it's because we now mostly read code as diffs, where a call often shows up without its signature or the code around it. what do you think about this?