Custom Hooks Flashcards
6 cards from real React practice questions. Tap to flip, then mark Knew It or Still Learning โ missed cards come back until you master them.
Read the first 6 Custom Hooks flashcards as text
What is the purpose of a useDebounce custom hook?
Answer: To delay updating a value until the user stops changing it for a specified time
useDebounce delays propagating a value change until a quiet period elapses, reducing rapid-fire side effects.
How does a usePrevious custom hook work?
Answer: It stores the current value in a ref after each render and returns the previous render's value
A useEffect inside the hook updates the ref after each render, so the ref holds the value from the previous render.
What is a useOnClickOutside custom hook typically used for?
Answer: Detecting clicks outside a referenced element to close dropdowns or modals
useOnClickOutside attaches a document click listener and fires a callback when the click target is outside the given ref.
Why should custom hooks avoid directly modifying DOM nodes without going through React?
Answer: Imperative DOM mutations can conflict with React's virtual DOM reconciliation
React controls the DOM via reconciliation; bypassing it with direct mutations can cause inconsistencies and bugs.
How does a useToggle custom hook differ from a plain useState(false) call?
Answer: useToggle encapsulates the toggle logic so consumers only get [value, toggle] without managing the setter
useToggle hides the setter and exposes a stable toggle function, reducing boilerplate in every consumer.
What React utility can you use to create a stable function reference to expose from a custom hook?
Answer: useCallback
useCallback memoizes the function so the same reference is returned across renders unless dependencies change.
Written and edited by Nathan Beja, founder of Practice Test Geeks, with AI assistance. We have not yet matched this exam's facts to an official source, so confirm fees, dates and rules with the exam body. Editorial policy