Use named returns for richer APIs.
Section: Custom Hook Patterns
Return object from a custom hook
tsx
tsx
function useDisclosure(initial = false) {
const [isOpen, setIsOpen] = useState(initial);
return {
isOpen,
open: () => setIsOpen(true),
close: () => setIsOpen(false),
toggle: () => setIsOpen(v => !v),
};
}Explanation
Objects are easier to read at call sites when hooks return several values or actions.
Learn the surrounding workflow
Compare similar commands or jump into common fixes when this command is part of a bigger troubleshooting path.
Related commands
Same sheet · prioritizing Custom Hook Patterns