What is a custom hook in React?
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.
Verify This Answer
Cross-check this information using these trusted sources:
More FAQs in What Are Custom Hooks in React and When Should You Write One?
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.
It is not just convention. The 'use' prefix lets the hooks lint plugin verify you follow the rules of hooks inside the custom hook, and it signals to readers that the function uses hooks and must follow their rules.
Still have questions?
Browse all our FAQs or reach out to our support team
