Whatever makes the calling code clearest. A custom hook can return a single value, an array like useState does, or an object. Arrays are common when there are exactly two related values, like state and a setter.
What Are Custom Hooks in React and When Should You Write One?
What should a custom hook return?
The answer
More FAQs in What Are Custom Hooks in React and When Should You Write One?
A custom hook is a function whose name starts with 'use' that can call other hooks. It lets you extract stateful logic from a component into a reusable function that other components and hooks can call.
When the same stateful logic appears in multiple components, or when a component's logic is complex enough that extracting it improves clarity. Common examples include useFetch, useForm, and useLocalStorage hooks.
When the logic has no state or effects. A pure function that formats a date or sorts an array is a utility function, not a hook. Hooks are specifically for stateful, effectful logic.
Still have questions?
Browse all our FAQs or reach out to our support team
Want to upskill yourself?
Your learning library
Small steps. Big possibilities.
Find your next course. Build something great.