Recall & Review
beginner
Why must React hooks start with the word
use?React requires hooks to start with
use so it can identify them as hooks and apply the rules of hooks correctly during rendering.Click to reveal answer
beginner
What is a good naming practice for custom hooks in React?
Custom hooks should start with
use followed by a descriptive name that explains what the hook does, like useFetchData or useToggle.Click to reveal answer
intermediate
Can you name a hook that does NOT follow the naming convention and explain why it is a problem?
A hook named
fetchData without the use prefix breaks the naming convention. React won't recognize it as a hook, which can cause bugs or warnings.Click to reveal answer
intermediate
What happens if you call a hook inside a regular JavaScript function that does not start with
use?React's Rules of Hooks require hooks to be called only at the top level of React function components or custom hooks. Calling hooks from regular JavaScript functions can break the rules of hooks and cause errors or unexpected behavior.
Click to reveal answer
beginner
How does following hook naming conventions help your React app?
It helps React detect hooks automatically, enforces rules to avoid bugs, and makes your code easier to read and maintain by other developers.
Click to reveal answer
Which of these is a valid React hook name?
✗ Incorrect
Hooks must start with 'use' to be recognized by React. 'useDataFetch' follows this rule.
Why should custom hooks start with 'use'?
✗ Incorrect
React uses the 'use' prefix to identify hooks and enforce rules like calling hooks only at the top level.
What is a consequence of not following hook naming conventions?
✗ Incorrect
React relies on naming conventions to detect hooks. Breaking them can cause bugs or warnings.
Which of these is NOT a valid hook name?
✗ Incorrect
'toggleUse' does not start with 'use' and so is not a valid hook name.
Where should hooks be called in React components?
✗ Incorrect
Hooks must be called at the top level of React function components (or custom hooks) to follow the rules of hooks.
Explain why React hooks must start with 'use' and how this affects your code.
Think about how React knows which functions are hooks.
You got /4 concepts.
Describe best practices for naming custom hooks in React.
Consider how you would name a function that fetches data or toggles a value.
You got /4 concepts.