react-hooks-strict-return
Limits custom hooks to returning an object or a tuple with at most two items.
Rule details Suggestion
Section titled “Rule details ”SuggestionThe rule checks functions whose names look like hooks, such as useThing, and reports returns that resolve to more than
two tuple items.
Returning an object is always allowed. Returning one or two array items is also allowed. Once a hook returns three or more positional values, the rule reports it and asks you to switch to named properties instead.
Examples
Section titled “Examples” Incorrect
function useData() { return [state, setState, loading, error];} Correct
function useToggle() { return [isOpen, setIsOpen];}
function useData() { return { state, setState, loading, error };}Related rules
Section titled “Related rules” require-named-effect-functions Keeps effect callbacks readable in stack traces
use-hook-at-top-level Keeps hook calls in a predictable place