Hooks interview questions
Practice 118 questions on hooks. Each runs in a real in-browser editor with Jest tests and a worked, diagram-backed solution.
118 questions
- JavaScriptCoding exercise
useBoolean
EASYImplement a hook that exposes a boolean value alongside setTrue, setFalse, and toggle helpers.
15 minPractice - JavaScriptCoding exercise
useClickAnywhere
EASYImplement a hook that fires a callback whenever the user clicks anywhere in the window, cleaning up on unmount.
15 minPractice - JavaScriptCoding exercise
useCopyToClipboard
EASYImplement a hook returning the last copied text and an async copy function built on the Clipboard API.
15 minPractice - JavaScriptCoding exercise
useCounter
EASYImplement a hook that exposes a numeric count along with increment, decrement, and reset helpers.
15 minPractice - JavaScriptCoding exercise
useCounter II
EASYRewrite useCounter so the returned helpers keep stable identities across renders.
15 minPractice - JavaScriptCoding exercise
useCycle
EASYImplement a hook that returns the current value of a sequence and advances to the next on demand.
15 minPractice - JavaScriptCoding exercise
useCycleList
EASYImplement a hook that steps through an array with wraparound, exposing the current item and next/prev/set.
15 minPractice - JavaScriptCoding exercise
useDefault
EASYImplement a hook that falls back to a default value whenever the underlying state becomes null or undefined.
15 minPractice - JavaScriptCoding exercise
useDocumentTitle
EASYImplement a hook that sets document.title and restores the previous title when the component unmounts.
15 minPractice - JavaScriptCoding exercise
useEffectOnce
EASYImplement a hook that runs the given effect a single time after mount, regardless of subsequent renders.
15 minPractice - JavaScriptCoding exercise
useFavicon
EASYImplement a hook that swaps the page favicon imperatively to a given URL.
15 minPractice - JavaScriptCoding exercise
useFocus
EASYImplement a hook that exposes a ref plus a function to focus the attached element on demand.
15 minPractice - JavaScriptCoding exercise
useHover
EASYImplement a hook that reports whether a referenced element is currently being hovered.
15 minPractice - JavaScriptCoding exercise
useIsFirstRender
EASYImplement a hook that returns true only on the first render and false on every render after.
15 minPractice - JavaScriptCoding exercise
useIsMounted
EASYImplement a hook returning a function that reports whether the component is still mounted, to guard async setState.
15 minPractice - JavaScriptCoding exercise
useLatest
EASYImplement a hook that returns a ref always holding the newest value, so callbacks and effects can read it without going stale.
15 minPractice - JavaScriptCoding exercise
useLocalStorage
EASYImplement a useState-like hook that persists to localStorage, with SSR-safe init and cross-tab sync.
15 minPractice - JavaScriptCoding exercise
useObject
EASYImplement a hook that holds an object in state and exposes helpers to merge updates or reset its value.
15 minPractice - JavaScriptCoding exercise
usePrevious
EASYImplement a hook that remembers and returns the value a state held on the previous render.
15 minPractice - JavaScriptCoding exercise
useRenderCount
EASYImplement a hook that counts how many times a component has rendered, without causing extra renders.
15 minPractice - JavaScriptCoding exercise
useSessionStorage
EASYImplement a useState-like hook backed by sessionStorage, with a graceful fallback when it is unavailable.
15 minPractice - JavaScriptCoding exercise
useSet
EASYImplement a hook that stores a Set in state and exposes add, delete, has, and clear helpers.
15 minPractice - JavaScriptCoding exercise
useStateWithReset
EASYImplement a useState-like hook that also returns a reset function which restores the initial value.
15 minPractice - JavaScriptCoding exercise
useToggle
EASYImplement a hook that holds a boolean and returns a stable toggle function to flip its value.
15 minPractice - JavaScriptCoding exercise
useUpdateEffect
EASYImplement a useEffect variant that skips the first render and fires only on subsequent updates.
15 minPractice - JavaScriptCoding exercise
useWindowSize
EASYImplement a hook that returns the current window width and height, updating on resize.
15 minPractice - JavaScriptCoding exercise
createGlobalState
MEDIUMBuild a useState shared by every component that calls it, by subscribing React to a store that lives outside it.
25 minPractice - JavaScriptCoding exercise
createStore + useSelector
MEDIUMBuild a store whose subscribers each re-render only when the slice they selected changes.
25 minPractice - JavaScriptCoding exercise
Plugin Hook Registry
MEDIUMBuild a WordPress/Tapable-style hook system where plugins tap named actions and filters that run in priority order.
25 minPremium questionPractice - JavaScriptCoding exercise
useActionState
MEDIUMImplement a hook that threads state through an async action, folding the previous state into the next and exposing a pending flag.
25 minPractice - JavaScriptCoding exercise
useArray
MEDIUMImplement a hook that manages an array along with helpers to push, remove, update, and clear items.
25 minUberPractice - JavaScriptCoding exercise
useAsync
MEDIUMImplement a hook that runs an async function and tracks its status, value, and error, with a manual execute trigger.
25 minPractice - JavaScriptCoding exercise
useAsyncRetry
MEDIUMImplement an async hook that exposes a retry function to re-run the last operation on demand.
25 minPractice - JavaScriptCoding exercise
useBeforeUnload
MEDIUMImplement a hook that warns before leaving a page while unsaved work exists.
25 minPractice - JavaScriptCoding exercise
useBoolean II
MEDIUMImplement an optimized useBoolean hook whose returned setters keep stable identity across renders.
25 minPremium questionPractice - JavaScriptCoding exercise
useBreakpoint
MEDIUMImplement a hook that returns the active responsive breakpoint name derived from the current window width.
25 minPractice - JavaScriptCoding exercise
useBroadcastChannel
MEDIUMImplement a hook that opens a named BroadcastChannel, delivers messages to the latest callback, posts data, and closes cleanly.
25 minPractice - JavaScriptCoding exercise
useClickOutside
MEDIUMImplement a hook that fires a callback when a pointer event lands outside a referenced element.
25 minPractice - JavaScriptCoding exercise
useContextSelector
MEDIUMSubscribe a component to one slice of a context so a change elsewhere in it does not re-render the whole tree.
25 minPractice - JavaScriptCoding exercise
useControllableValue
MEDIUMImplement a hook that lets one component work both controlled and uncontrolled, deciding the mode from its props.
25 minPractice - JavaScriptCoding exercise
useCookieState
MEDIUMImplement a useState backed by a cookie — state the server can also write, with no event when it does.
25 minPractice - JavaScriptCoding exercise
useCountdown
MEDIUMImplement a hook that drives a countdown timer with start, pause, and reset controls.
25 minWalmartPractice - JavaScriptCoding exercise
useCountUp
MEDIUMImplement a hook that animates a number to a target over a fixed duration, independent of the display's framerate.
25 minPractice - JavaScriptCoding exercise
useDarkMode
MEDIUMImplement a hook that tracks the system dark-color-scheme preference through matchMedia and updates when it changes.
25 minPractice - JavaScriptCoding exercise
useDebounce
MEDIUMImplement a hook that returns a debounced version of a value, updating only after a quiet period.
25 minAdobe · UberPractice - JavaScriptCoding exercise
useDeepCompareEffect
MEDIUMImplement a useEffect that re-runs when its dependencies change by value, not by reference.
25 minPractice - JavaScriptCoding exercise
useDropArea
MEDIUMImplement a hook that turns any element into a drop zone for files, text, and links, tracking drag-over state.
25 minPractice - JavaScriptCoding exercise
useDynamicList
MEDIUMImplement a hook that manages a list whose items keep stable keys across inserts, removals, and reorders.
25 minPractice - JavaScriptCoding exercise
useElementBounding
MEDIUMImplement a hook that tracks an element's size and position, staying correct across scroll, resize, and content changes.
25 minPractice - JavaScriptCoding exercise
useEventCallback
MEDIUMImplement a hook returning a stable callback that always sees the latest props and state, avoiding stale closures.
25 minPractice - JavaScriptCoding exercise
useEventListener
MEDIUMImplement a hook that attaches and cleans up a browser event listener on a target element or window.
25 minPractice - JavaScriptCoding exercise
useFetch
MEDIUMImplement a data-fetching hook exposing data, error, and loading, that refetches when the URL changes and ignores stale responses.
25 minPractice - JavaScriptCoding exercise
useFocusTrap
MEDIUMImplement a hook that traps keyboard focus inside a container while it is active and restores it on release.
25 minPractice - JavaScriptCoding exercise
useFocusWithin
MEDIUMImplement a hook that reports whether keyboard focus is anywhere inside a container, without flickering as focus moves between children.
25 minPractice - JavaScriptCoding exercise
useFullscreen
MEDIUMImplement a hook that enters, exits, and tracks fullscreen mode for a referenced element through the Fullscreen API.
25 minPractice - JavaScriptCoding exercise
useGeolocation
MEDIUMImplement a hook wrapping the Geolocation API to expose position, error, and loading state.
25 minPractice - JavaScriptCoding exercise
useGetState
MEDIUMImplement a useState variant that also returns a getter for reading the newest state from inside stale closures.
25 minPractice - JavaScriptCoding exercise
useHotkeys
MEDIUMImplement a hook that binds a shortcut like ctrl+k, matching modifiers exactly and ignoring typing in inputs.
25 minPractice - JavaScriptCoding exercise
useIdle
MEDIUMImplement a hook that flags the user as idle after a period without keyboard, pointer, or scroll activity.
25 minPractice - JavaScriptCoding exercise
useImageOnLoad
MEDIUMImplement a hook that tracks an image's loading, loaded, and error state, handling images already in cache.
25 minPractice - JavaScriptCoding exercise
useImmerReducer
MEDIUMWrite a reducer whose body mutates a draft, getting an immutable next state that a reducer is required to return.
25 minPractice - JavaScriptCoding exercise
useInputControl
MEDIUMImplement a hook that manages a controlled input value alongside its dirty and touched flags.
25 minPractice - JavaScriptCoding exercise
useIntersectionObserver
MEDIUMImplement a hook that reports whether a ref'd element is intersecting the viewport via IntersectionObserver.
25 minPractice - JavaScriptCoding exercise
useInterval
MEDIUMImplement a hook that runs a callback on a timer with a configurable, pauseable delay.
25 minPractice - JavaScriptCoding exercise
useKeyPress
MEDIUMImplement a hook that returns whether a given key is currently being pressed on the keyboard.
25 minPractice - JavaScriptCoding exercise
useList
MEDIUMImplement a hook managing an array with immutable helpers — push, removeAt, updateAt, insertAt, clear, and set.
25 minPractice - JavaScriptCoding exercise
useLockBodyScroll
MEDIUMImplement a hook that freezes page scrolling while a modal or drawer is open, coordinating nested locks.
25 minPractice - JavaScriptCoding exercise
useLockFn
MEDIUMImplement a hook that wraps an async function so it cannot run again while a previous call is still in flight, preventing double-submits.
25 minPractice - JavaScriptCoding exercise
useLongPress
MEDIUMImplement a hook that fires a callback after a pointer is held down past a delay, cancelling on early release or move.
25 minPractice - JavaScriptCoding exercise
useMap
MEDIUMImplement a hook that wraps a JavaScript Map with set, delete, and clear helpers backed by state.
25 minPractice - JavaScriptCoding exercise
useMediaQuery
MEDIUMImplement a hook that returns whether a media query currently matches and updates on changes.
25 minPractice - JavaScriptCoding exercise
useMediatedState
MEDIUMImplement a useState-like hook that runs every incoming value through a mediator before committing it.
25 minPractice - JavaScriptCoding exercise
useMethods
MEDIUMImplement a hook that turns a map of state transitions into bound, stable action methods over a reducer.
25 minPractice - JavaScriptCoding exercise
useNetworkState
MEDIUMImplement a hook that reports online/offline status and connection info from the Network Information API.
25 minPractice - JavaScriptCoding exercise
useNotification
MEDIUMImplement a hook that tracks notification permission and safely requests and displays browser notifications.
25 minPractice - JavaScriptCoding exercise
useOptimistic
MEDIUMImplement a hook that shows an optimistic value while an update is in flight, then reconciles to the real value.
25 minPractice - JavaScriptCoding exercise
useOrientation
MEDIUMImplement a hook that reports the screen orientation type and angle and updates when the Screen Orientation API changes.
25 minPractice - JavaScriptCoding exercise
usePageVisibility
MEDIUMImplement a hook that reports whether the document is visible or hidden and updates on visibilitychange.
25 minPractice - JavaScriptCoding exercise
usePagination
MEDIUMImplement a hook that manages page state over a total count, exposing page, pageCount, and next/prev/go with clamping.
25 minPractice - JavaScriptCoding exercise
usePermission
MEDIUMImplement a hook that queries a browser permission, tracks changes, and handles unsupported or failed queries.
25 minPractice - JavaScriptCoding exercise
usePreferredLanguage
MEDIUMImplement a hook that reports the browser's primary preferred language and updates when the preference changes.
25 minPractice - JavaScriptCoding exercise
usePrefersReducedMotion
MEDIUMImplement a hook that tracks the system reduced-motion accessibility preference through matchMedia and updates when it changes.
25 minPractice - JavaScriptCoding exercise
usePreviousDistinct
MEDIUMImplement a hook that remembers the last value that actually differed from the current one, with a customizable comparator.
25 minPractice - JavaScriptCoding exercise
useQuery
MEDIUMImplement a hook that tracks the loading, data, and error states of a promise-returning request.
25 minPractice - JavaScriptCoding exercise
useQueue
MEDIUMImplement a hook wrapping a FIFO queue with add, remove, clear, and first/last/size accessors.
25 minPractice - JavaScriptCoding exercise
useRafState
MEDIUMImplement a useState variant that defers commits to the next animation frame, so rapid updates coalesce to at most one render per frame.
25 minPractice - JavaScriptCoding exercise
useReactive
MEDIUMImplement a hook whose state object you mutate directly, and reckon with what that costs React.
25 minPractice - JavaScriptCoding exercise
useRovingTabIndex
MEDIUMImplement a hook that gives a widget arrow-key navigation, keeping exactly one item in the tab order at a time.
25 minPractice - JavaScriptCoding exercise
useScript
MEDIUMImplement a hook that injects an external script tag and reports its loading status, deduping repeated sources.
25 minPractice - JavaScriptCoding exercise
useScrollDirection
MEDIUMImplement a hook that reports whether the user is scrolling up or down, ignoring jitter below a threshold.
25 minPractice - JavaScriptCoding exercise
useScrollPosition
MEDIUMImplement a hook that tracks the window scroll x/y position with a passive listener, throttled with rAF.
25 minPractice - JavaScriptCoding exercise
useSelections
MEDIUMImplement a hook that tracks a multi-select over a list, with an all/none/partial header state that stays honest.
25 minPractice - JavaScriptCoding exercise
useStateWithHistory
MEDIUMImplement a useState variant that records value history and exposes back, forward, and go over it.
25 minPractice - JavaScriptCoding exercise
useStep
MEDIUMImplement a hook that drives a multi-step flow with next, previous, reset, and bounded index controls.
25 minPractice - JavaScriptCoding exercise
useSwipe
MEDIUMImplement a hook that detects swipe gestures on an element, reporting direction once a drag passes a threshold.
25 minPractice - JavaScriptCoding exercise
useSyncExternalStore
MEDIUMImplement the useSyncExternalStore shim — subscribe to an external store and read a consistent snapshot, re-rendering when it changes without missing an update.
25 minPractice - JavaScriptCoding exercise
useTextareaAutosize
MEDIUMImplement a React hook that grows and shrinks a textarea to fit its content as the user types.
25 minPractice - JavaScriptCoding exercise
useTextSelection
MEDIUMImplement a hook that reports the user's current text selection as live, plain state, updating as the selection changes.
25 minPractice - JavaScriptCoding exercise
useThrottle
MEDIUMImplement a hook that returns a throttled copy of a value, updating at most once per given interval.
25 minDiscord · Netflix · UberPractice - JavaScriptCoding exercise
useTimeAgo
MEDIUMImplement a hook that formats a timestamp as relative time like "3 minutes ago" and refreshes itself as time passes.
25 minPractice - JavaScriptCoding exercise
useTimeout
MEDIUMImplement a hook that runs a callback after a given delay and cleans up when the component unmounts.
25 minPractice - JavaScriptCoding exercise
useTrackedEffect
MEDIUMImplement an effect that also tells you which of its dependencies changed since the last run.
25 minPractice - JavaScriptCoding exercise
useUrlState
MEDIUMImplement a useState that lives in the query string, staying shareable without burying the back button.
25 minPractice - JavaScriptCoding exercise
useValidatedState
MEDIUMImplement a useState variant that reports whether the current value passes a validator, without an extra render.
25 minPractice - JavaScriptCoding exercise
useVibrate
MEDIUMImplement a hook that detects the Vibration API and exposes stable methods to start a pattern or cancel it.
25 minPractice - JavaScriptCoding exercise
useWakeLock
MEDIUMImplement a hook that requests, releases, and tracks a screen wake lock, including browser-initiated release.
25 minPractice - JavaScriptCoding exercise
useWebShare
MEDIUMImplement a hook that detects Web Share support, validates share data when possible, and invokes the native share sheet.
25 minPractice - JavaScriptCoding exercise
useWhyDidYouUpdate
MEDIUMImplement a debugging hook that logs which props changed between renders.
25 minPractice - JavaScriptCoding exercise
useDebouncedCallback
HARDImplement a hook returning a debounced callback with cancel and flush, always calling the latest function.
40 minPremium questionPractice - JavaScriptCoding exercise
useDraggable
HARDImplement a pointer-based drag hook that tracks an element's x/y offset with start/move/end handlers.
40 minPremium questionPractice - JavaScriptCoding exercise
useForm
HARDImplement a form-state hook managing values, touched, errors, validation, and submission.
40 minPremium questionPractice - JavaScriptCoding exercise
useInfiniteScroll
HARDImplement a hook that loads more pages when a sentinel element scrolls into view, guarding against duplicate loads.
40 minPremium questionPractice - JavaScriptCoding exercise
useResizeObserver
HARDImplement a hook that reports a ref'd element's content-box size via ResizeObserver.
40 minPremium questionPractice - JavaScriptCoding exercise
useSWR
HARDImplement a stale-while-revalidate data hook with an in-memory cache, dedup, and revalidation shared across components.
40 minPremium questionPractice - JavaScriptCoding exercise
useThrottledCallback
HARDImplement a hook returning a throttled version of a callback that runs at most once per interval, with leading/trailing calls.
40 minPremium questionPractice - JavaScriptCoding exercise
useUndoRedo
HARDImplement an undo/redo state hook exposing undo, redo, canUndo, canRedo over past/present/future stacks.
40 minPremium questionPractice - JavaScriptCoding exercise
useVirtualList
HARDImplement a windowing hook that renders only the visible rows of a long list, with correct spacer offsets.
40 minPremium questionPractice - JavaScriptCoding exercise
useWebSocket
HARDImplement a WebSocket hook exposing connection status, last message, and send, with auto-reconnect and cleanup.
40 minPremium questionPractice