0
0
Reactframework~20 mins

Hook naming conventions in React - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Hook Naming Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Why must React hooks start with 'use'?

React hooks must start with the word use. Why is this naming rule important?

AReact uses the 'use' prefix to identify hooks and enforce rules about their usage.
BThe 'use' prefix is required to make hooks compatible with older React versions.
CHooks must start with 'use' to make them asynchronous functions.
DIt is a stylistic choice with no effect on how React works.
Attempts:
2 left
💡 Hint

Think about how React detects hooks inside components.

📝 Syntax
intermediate
1:30remaining
Which hook name is valid according to React conventions?

Choose the valid React hook name from the options below.

AdataUseFetch
BfetchDataHook
ChookUseData
DuseDataFetch
Attempts:
2 left
💡 Hint

Remember hooks must start with 'use'.

component_behavior
advanced
2:00remaining
What happens if a custom hook does NOT start with 'use'?

Consider a custom hook named fetchData (without 'use' prefix). What is the likely behavior when used inside a React component?

AReact will treat it as a hook anyway because it is called inside a component.
BReact will not recognize it as a hook and may break the rules of hooks, causing bugs or warnings.
CThe hook will run twice on every render.
DReact will throw a syntax error during compilation.
Attempts:
2 left
💡 Hint

Think about how React enforces hook rules.

🔧 Debug
advanced
2:30remaining
Identify the naming error causing a React warning

Given this custom hook code, which naming mistake causes React to warn about invalid hook usage?

function fetchUserData() {
  const [user, setUser] = React.useState(null);
  // ...fetch logic
  return user;
}
AThe hook must return an array, not a single value.
BThe hook should be declared inside the component, not outside.
CThe function name should start with 'use' like 'useFetchUserData'.
DReact hooks cannot use useState inside custom hooks.
Attempts:
2 left
💡 Hint

Check the function name against React hook naming rules.

state_output
expert
3:00remaining
What is the output of this React component using a custom hook with incorrect naming?

Consider this React component and custom hook:

function fetchCount() {
  const [count, setCount] = React.useState(0);
  React.useEffect(() => {
    const timer = setInterval(() => setCount(c => c + 1), 1000);
    return () => clearInterval(timer);
  }, []);
  return count;
}

function Counter() {
  const count = fetchCount();
  return 
{count}
; }

What will happen when <Counter /> is rendered?

AReact will render the count but show a warning about invalid hook call due to naming.
BReact will render the count and update it every second without warnings.
CReact will throw a runtime error because hooks cannot be called inside functions without 'use' prefix.
DReact will render '0' once and never update the count.
Attempts:
2 left
💡 Hint

Consider React's hook rules and naming conventions.