Hooks interview questions
Practice 82 questions on hooks. Each runs in a real in-browser editor with Jest tests and a worked, diagram-backed solution.
82 questions
- EASY
useBoolean
Implement a hook that exposes a boolean value alongside setTrue, setFalse, and toggle helpers.
15 minJavaScript - EASY
useClickAnywhere
Implement a hook that fires a callback whenever the user clicks anywhere in the window, cleaning up on unmount.
15 minJavaScript - EASY
useCopyToClipboard
Implement a hook returning the last copied text and an async copy function built on the Clipboard API.
15 minJavaScript - EASY
useCounter
Implement a hook that exposes a numeric count along with increment, decrement, and reset helpers.
15 minJavaScript - EASY
useCounter II
Rewrite useCounter so the returned helpers keep stable identities across renders.
15 minJavaScript - EASY
useCycle
Implement a hook that returns the current value of a sequence and advances to the next on demand.
15 minJavaScript - EASY
useCycleList
Implement a hook that steps through an array with wraparound, exposing the current item and next/prev/set.
15 minJavaScript - EASY
useDefault
Implement a hook that falls back to a default value whenever the underlying state becomes null or undefined.
15 minJavaScript - EASY
useDocumentTitle
Implement a hook that sets document.title and restores the previous title when the component unmounts.
15 minJavaScript - EASY
useEffectOnce
Implement a hook that runs the given effect a single time after mount, regardless of subsequent renders.
15 minJavaScript - EASY
useFavicon
Implement a hook that swaps the page favicon imperatively to a given URL.
15 minJavaScript - EASY
useFocus
Implement a hook that exposes a ref plus a function to focus the attached element on demand.
15 minJavaScript - EASY
useHover
Implement a hook that reports whether a referenced element is currently being hovered.
15 minJavaScript - EASY
useIsFirstRender
Implement a hook that returns true only on the first render and false on every render after.
15 minJavaScript - EASY
useIsMounted
Implement a hook returning a function that reports whether the component is still mounted, to guard async setState.
15 minJavaScript - EASY
useLatest
Implement a hook that returns a ref always holding the newest value, so callbacks and effects can read it without going stale.
15 minJavaScript - EASY
useLocalStorage
Implement a useState-like hook that persists to localStorage, with SSR-safe init and cross-tab sync.
15 minJavaScript - EASY
useObject
Implement a hook that holds an object in state and exposes helpers to merge updates or reset its value.
15 minJavaScript - EASY
usePrevious
Implement a hook that remembers and returns the value a state held on the previous render.
15 minJavaScript - EASY
useRenderCount
Implement a hook that counts how many times a component has rendered, without causing extra renders.
15 minJavaScript - EASY
useSessionStorage
Implement a useState-like hook backed by sessionStorage, with a graceful fallback when it is unavailable.
15 minJavaScript - EASY
useSet
Implement a hook that stores a Set in state and exposes add, delete, has, and clear helpers.
15 minJavaScript - EASY
useStateWithReset
Implement a useState-like hook that also returns a reset function which restores the initial value.
15 minJavaScript - EASY
useToggle
Implement a hook that holds a boolean and returns a stable toggle function to flip its value.
15 minJavaScript - EASY
useUpdateEffect
Implement a useEffect variant that skips the first render and fires only on subsequent updates.
15 minJavaScript - EASY
useWindowSize
Implement a hook that returns the current window width and height, updating on resize.
15 minJavaScript - MEDIUM
createGlobalState
Build a useState shared by every component that calls it, by subscribing React to a store that lives outside it.
25 minJavaScript - MEDIUM
createStore + useSelector
Build a store whose subscribers each re-render only when the slice they selected changes.
25 minJavaScript - MEDIUM
Plugin Hook Registry
Build a WordPress/Tapable-style hook system where plugins tap named actions and filters that run in priority order.
25 minJavaScript - MEDIUM
useArray
Implement a hook that manages an array along with helpers to push, remove, update, and clear items.
25 minJavaScript - MEDIUM
useAsync
Implement a hook that runs an async function and tracks its status, value, and error, with a manual execute trigger.
25 minJavaScript - MEDIUM
useAsyncRetry
Implement an async hook that exposes a retry function to re-run the last operation on demand.
25 minJavaScript - MEDIUM
useBoolean II
Implement an optimized useBoolean hook whose returned setters keep stable identity across renders.
25 minJavaScript - MEDIUM
useBreakpoint
Implement a hook that returns the active responsive breakpoint name derived from the current window width.
25 minJavaScript - MEDIUM
useClickOutside
Implement a hook that fires a callback when a pointer event lands outside a referenced element.
25 minJavaScript - MEDIUM
useControllableValue
PREMIUMImplement a hook that lets one component work both controlled and uncontrolled, deciding the mode from its props.
25 minJavaScript - MEDIUM
useCookieState
Implement a useState backed by a cookie — state the server can also write, with no event when it does.
25 minJavaScript - MEDIUM
useCountdown
Implement a hook that drives a countdown timer with start, pause, and reset controls.
25 minJavaScript - MEDIUM
useDebounce
PREMIUMImplement a hook that returns a debounced version of a value, updating only after a quiet period.
25 minJavaScript - MEDIUM
useDynamicList
Implement a hook that manages a list whose items keep stable keys across inserts, removals, and reorders.
25 minJavaScript - MEDIUM
useEventCallback
Implement a hook returning a stable callback that always sees the latest props and state, avoiding stale closures.
25 minJavaScript - MEDIUM
useEventListener
Implement a hook that attaches and cleans up a browser event listener on a target element or window.
25 minJavaScript - MEDIUM
useFetch
Implement a data-fetching hook exposing data, error, and loading, that refetches when the URL changes and ignores stale responses.
25 minJavaScript - MEDIUM
useGeolocation
Implement a hook wrapping the Geolocation API to expose position, error, and loading state.
25 minJavaScript - MEDIUM
useGetState
Implement a useState variant that also returns a getter for reading the newest state from inside stale closures.
25 minJavaScript - MEDIUM
useIdle
Implement a hook that flags the user as idle after a period without keyboard, pointer, or scroll activity.
25 minJavaScript - MEDIUM
useInputControl
Implement a hook that manages a controlled input value alongside its dirty and touched flags.
25 minJavaScript - MEDIUM
useIntersectionObserver
Implement a hook that reports whether a ref'd element is intersecting the viewport via IntersectionObserver.
25 minJavaScript - MEDIUM
useInterval
Implement a hook that runs a callback on a timer with a configurable, pauseable delay.
25 minJavaScript - MEDIUM
useKeyPress
Implement a hook that returns whether a given key is currently being pressed on the keyboard.
25 minJavaScript - MEDIUM
useList
Implement a hook managing an array with immutable helpers — push, removeAt, updateAt, insertAt, clear, and set.
25 minJavaScript - MEDIUM
useLongPress
Implement a hook that fires a callback after a pointer is held down past a delay, cancelling on early release or move.
25 minJavaScript - MEDIUM
useMap
Implement a hook that wraps a JavaScript Map with set, delete, and clear helpers backed by state.
25 minJavaScript - MEDIUM
useMediaQuery
Implement a hook that returns whether a media query currently matches and updates on changes.
25 minJavaScript - MEDIUM
useMediatedState
Implement a useState-like hook that runs every incoming value through a mediator before committing it.
25 minJavaScript - MEDIUM
useMethods
Implement a hook that turns a map of state transitions into bound, stable action methods over a reducer.
25 minJavaScript - MEDIUM
useNetworkState
Implement a hook that reports online/offline status and connection info from the Network Information API.
25 minJavaScript - MEDIUM
usePagination
Implement a hook that manages page state over a total count, exposing page, pageCount, and next/prev/go with clamping.
25 minJavaScript - MEDIUM
usePreviousDistinct
Implement a hook that remembers the last value that actually differed from the current one, with a customizable comparator.
25 minJavaScript - MEDIUM
useQuery
Implement a hook that tracks the loading, data, and error states of a promise-returning request.
25 minJavaScript - MEDIUM
useQueue
Implement a hook wrapping a FIFO queue with add, remove, clear, and first/last/size accessors.
25 minJavaScript - MEDIUM
useReactive
Implement a hook whose state object you mutate directly, and reckon with what that costs React.
25 minJavaScript - MEDIUM
useScript
Implement a hook that injects an external script tag and reports its loading status, deduping repeated sources.
25 minJavaScript - MEDIUM
useScrollPosition
Implement a hook that tracks the window scroll x/y position with a passive listener, throttled with rAF.
25 minJavaScript - MEDIUM
useSelections
Implement a hook that tracks a multi-select over a list, with an all/none/partial header state that stays honest.
25 minJavaScript - MEDIUM
useStateWithHistory
Implement a useState variant that records value history and exposes back, forward, and go over it.
25 minJavaScript - MEDIUM
useStep
Implement a hook that drives a multi-step flow with next, previous, reset, and bounded index controls.
25 minJavaScript - MEDIUM
useThrottle
PREMIUMImplement a hook that returns a throttled copy of a value, updating at most once per given interval.
25 minJavaScript - MEDIUM
useTimeout
Implement a hook that runs a callback after a given delay and cleans up when the component unmounts.
25 minJavaScript - MEDIUM
useUrlState
Implement a useState that lives in the query string, staying shareable without burying the back button.
25 minJavaScript - MEDIUM
useValidatedState
Implement a useState variant that reports whether the current value passes a validator, without an extra render.
25 minJavaScript - MEDIUM
useWhyDidYouUpdate
Implement a debugging hook that logs which props changed between renders.
25 minJavaScript - HARD
useDebouncedCallback
PREMIUMImplement a hook returning a debounced callback with cancel and flush, always calling the latest function.
40 minJavaScript - HARD
useDraggable
PREMIUMImplement a pointer-based drag hook that tracks an element's x/y offset with start/move/end handlers.
40 minJavaScript - HARD
useForm
PREMIUMImplement a form-state hook managing values, touched, errors, validation, and submission.
40 minJavaScript - HARD
useInfiniteScroll
PREMIUMImplement a hook that loads more pages when a sentinel element scrolls into view, guarding against duplicate loads.
40 minJavaScript - HARD
useResizeObserver
PREMIUMImplement a hook that reports a ref'd element's content-box size via ResizeObserver.
40 minJavaScript - HARD
useSWR
PREMIUMImplement a stale-while-revalidate data hook with an in-memory cache, dedup, and revalidation shared across components.
40 minJavaScript - HARD
useThrottledCallback
PREMIUMImplement a hook returning a throttled version of a callback that runs at most once per interval, with leading/trailing calls.
40 minJavaScript - HARD
useUndoRedo
PREMIUMImplement an undo/redo state hook exposing undo, redo, canUndo, canRedo over past/present/future stacks.
40 minJavaScript - HARD
useVirtualList
PREMIUMImplement a windowing hook that renders only the visible rows of a long list, with correct spacer offsets.
40 minJavaScript - HARD
useWebSocket
PREMIUMImplement a WebSocket hook exposing connection status, last message, and send, with auto-reconnect and cleanup.
40 minJavaScript