React Hooks
State, effects, refs, memoization, transitions and building your own hooks.
1.What are the benefits of using hooks in React?
Reusable stateful logic, co-location by concern, and no classes.
2.What is the `useRef` hook in React and when should it be used?
A persistent mutable box for DOM nodes and values that don't affect rendering.
3.What are the rules of React hooks?
Top-level only, React functions only, why call order matters, and lint enforcement.
4.Why do my effects run twice in development, and how should I fix it?
Strict Mode's mount-unmount-mount check and how to write symmetric cleanups.
5.Digital Clock
Build a ticking digital clock that stays aligned to real seconds, with a 12/24-hour toggle and clean timer teardown.
6.What are Actions in React 19? Explain `useActionState` and `useFormStatus`
Async transitions for mutations with built-in pending, error and form-reset handling.
7.What is the React Compiler and how does it change memoization?
Build-time automatic memoization, its reliance on the Rules of React, and adoption.
8.What are some common pitfalls when doing data fetching in React?
Races, missing cleanup, waterfalls, missing caching and stale copies of server data.
9.What is React Strict Mode and what are its benefits?
Development-only checks: double rendering, effect re-runs, ref checks and deprecation warnings.
10.What does the `use` API do in React 19 and how is it different from other hooks?
Reading promises and context during render, conditional calls, and the cached-promise rule.
11.What is the `useCallback` hook in React and when should it be used?
Stable function identities, when they matter, and the React Compiler.
12.What is the `useMemo` hook in React and when should it be used?
Caching expensive calculations and stable identities, and when not to bother.
13.What is the purpose of callback function argument format of `setState()` in React and when should it be used?
Updater functions compute next state from the latest queued state.
14.What does the dependency array of `useEffect` affect?
When effects re-synchronize, Object.is comparison, and stale closures.
15.What is the difference between `useEffect` and `useLayoutEffect` in React?
Effect timing relative to paint, and when blocking paint is worth it.
16.Explain what happens when the `useState` setter function is called in React
Enqueue, schedule, batch, render, reconcile, commit, and the state snapshot.
17.Memory Game
Build a card-matching memory game with timed flip-back, move counting and screen-reader friendly announcements.
18.Progress Bars
Each click adds a progress bar that fills from 0 to 100% over two seconds, driven by requestAnimationFrame.
19.Stopwatch
Build an accurate stopwatch with start, stop, lap and reset, based on timestamps rather than counting ticks.
20.Traffic Light
Build a traffic light that cycles through configurable states with timers, a pause control and clean effect teardown.
21.Whack-a-Mole
Build a timed whack-a-mole game with random moles, scoring, a countdown and keyboard play, managing several timers safely.
22.Explain `useTransition` and `useDeferredValue` and when to use each
Marking updates as non-urgent so concurrent React keeps input responsive.
23.What is the `useId` hook in React and when should it be used?
SSR-safe unique ids for accessibility attributes, and why not for keys.
24.How do refs work as a prop in React 19, and what are ref cleanup functions?
ref as a regular prop, the end of forwardRef, and callback ref cleanups.
25.What is `forwardRef()` in React used for?
Passing refs through components, and why React 19 makes ref a regular prop.
26.How does `useOptimistic` work in React 19?
Optimistic overlays on real state during Actions, with automatic revert.
27.What is the `useReducer` hook in React and when should it be used?
Centralized, testable state transitions with a pure reducer and stable dispatch.
28.Analog Clock
Draw a ticking analog clock in SVG with correctly rotated hour, minute and second hands and an accessible name.
29.Grid Lights
Build a grid of toggle lights that, once all are lit, switch off one by one in reverse activation order.