Recall & Review
beginner
What is a custom hook in React?
A custom hook is a JavaScript function whose name starts with "use" and that can call other hooks. It lets you reuse stateful logic between components without changing their structure.
Click to reveal answer
beginner
Why should you start the name of a custom hook with "use"?
React uses the "use" prefix to identify hooks. This helps React enforce rules of hooks and enables linting tools to check correct usage.
Click to reveal answer
intermediate
How do custom hooks help in React development?
Custom hooks let you share logic like fetching data, managing forms, or animations across components. This keeps code clean and avoids repetition.Click to reveal answer
beginner
Can custom hooks use other hooks inside them?
Yes, custom hooks can call built-in hooks like useState, useEffect, or even other custom hooks to build complex reusable logic.
Click to reveal answer
beginner
What is a simple example of a custom hook?
A simple custom hook could be useCounter that uses useState to keep a count and returns the count and a function to increase it.
Click to reveal answer
What prefix must a custom hook's name start with in React?
✗ Incorrect
Custom hooks must start with "use" so React can identify them as hooks and apply rules correctly.
Which of these can a custom hook NOT do?
✗ Incorrect
Custom hooks do not return JSX. They return values or functions to be used inside components that return JSX.
Why use custom hooks instead of copying code between components?
✗ Incorrect
Custom hooks help keep code DRY by sharing logic instead of copying it.
Which React hook is commonly used inside custom hooks to manage state?
✗ Incorrect
useState is often used inside custom hooks to manage stateful values.
Can a custom hook call another custom hook?
✗ Incorrect
Custom hooks can call other custom hooks to compose complex logic.
Explain what a custom hook is and why it is useful in React.
Think about how you can share code between components without copying.
You got /5 concepts.
Describe how you would create a simple custom hook to manage a counter.
Start with useState and return what components need.
You got /4 concepts.