React Hooks API Tour Quiz
Six drills covering core hooks: a what-is-a-hook intro plus targeted exercises on useState, useRef, useLayoutEffect, useMemo, and useReducer with runnable examples.
Question Bank
Hard
JavaScript
quiz
react
hooks
interview-prep
899 views
7
Define what a React Hook is and state the two Rules of Hooks. Why does React require hooks to be called at the top level of a function component and not inside loops or conditions?
Examples
Example 1:
Input:
function X({ flag }) {
if (flag) {
const [v, setV] = useState(0); // illegal
}
return null;
}
Output: React warns/errors because the hook call order changes based on `flag`.
Explanation: React identifies hooks by call order across renders; a conditional call shifts every later hook by one slot and corrupts state.5 more questions, with full solutions and explanations, are available for premium members.
Upgrade to Premium