Recall & Review
beginner
What is a custom hook in React?
A custom hook is a JavaScript function that starts with 'use' and lets you reuse stateful logic between components without repeating code.
Click to reveal answer
beginner
Why do developers create custom hooks?
To share and reuse logic easily across multiple components, making code cleaner and easier to maintain.
Click to reveal answer
intermediate
How do custom hooks improve code organization?
They separate complex logic from UI code, so components stay simple and focused on rendering.
Click to reveal answer
intermediate
Can custom hooks use other hooks inside them?
Yes, custom hooks can use built-in hooks like useState or useEffect to manage state and side effects internally.
Click to reveal answer
beginner
Give an example scenario where a custom hook is useful.
When multiple components need to fetch data from the same API and handle loading and error states, a custom hook can manage this logic once and share it.
Click to reveal answer
What is the main reason to use a custom hook in React?
✗ Incorrect
Custom hooks help reuse logic like state and effects across components, avoiding code duplication.
Which of these is true about custom hooks?
✗ Incorrect
Custom hooks must start with 'use' so React can identify them as hooks.
Custom hooks help keep components:
✗ Incorrect
By moving logic to custom hooks, components stay clean and focused on rendering.
Can a custom hook use useState inside it?
✗ Incorrect
Custom hooks can use built-in hooks like useState to manage internal state.
Which naming convention is correct for a custom hook?
✗ Incorrect
Custom hooks must start with 'use' to follow React's rules and conventions.
Explain why custom hooks are useful in React and how they help with code reuse.
Think about how you might share the same behavior in many places without repeating code.
You got /4 concepts.
Describe how a custom hook can improve the organization of a React app's code.
Consider how moving logic out of components helps keep things tidy.
You got /4 concepts.