Custom Hook Rules
Question
What are the rules of custom hooks?
Hint
Custom hooks share stateful logic, not state itself.
Explanation
Custom hooks must follow two rules: 1) The name must start with "use" (useFetch, useLocalStorage) so React can identify it as a hook and the linter can check rules. 2) Only call other hooks (useState, useEffect, etc.) at the top level — not inside conditions, loops, or nested functions. Custom hooks let you extract and reuse stateful logic across components. Each component using the hook gets its own state — the hook shares logic, not state. Return whatever is useful (values, functions, objects).
Related Resources
Related Lessons
- Custom Hooks
Learn custom hooks.
Look up unfamiliar terms
A beginner-friendly glossary explains jargon in plain English — variables, functions, DOM, Promise, and more.
Decode error messages
Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.
Build real projects
Apply what you learned by building guided projects with starter code and solutions.