Skip to content

react-hooks-strict-return

Limits custom hooks to returning an object or a tuple with at most two items.

The 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.

Incorrect
function useData() {
return [state, setState, loading, error];
}
Correct
function useToggle() {
return [isOpen, setIsOpen];
}
function useData() {
return { state, setState, loading, error };
}