React Developer interview question · Most asked
A React page with a long list becomes slow when typing in a search box. How do you find and fix the problem?
Scenario Asked in Frontend Engineer · Full Stack Engineer interviews
Summary
Profile before changing code: the React DevTools Profiler shows which components re-render on each keystroke and
how long they take. Typical fixes are to stop the whole list re-rendering (memoise rows, keep state close to where
it's used), render only visible rows (virtualisation), and keep typing responsive with useDeferredValue or
useTransition while the filtered list updates.
Longer Answer
- Causes: search state stored high in the tree so every keystroke re-renders the page; new object or function
props each render defeating
memo; expensive filtering on every render; thousands of DOM nodes. - Fixes: move state down or split components;
React.memofor rows with stable props (useCallback,useMemowhere it matters, or the React Compiler);useMemofor the filtered array; virtualise with TanStack Virtual or react-window;useDeferredValue(query)so the input updates immediately. - Measure again: Profiler and the browser Performance panel (long tasks, INP).
- For very large data, filter on the server or in a web worker.
Key Points
- Profile first.
- Keep state close to where it's used.
- Memoise rows; stable props.
- Virtualise long lists.
- useDeferredValue keeps input responsive.
Explanation
What interviewers look for
Measuring first, then picking the right fix among state placement, memoisation, virtualisation and concurrent features.
More React Developer questions
- Explain React concept: keys in lists.
- Explain React concept: lifting state up.
- Explain React concept: props.
- Explain React concept: state.
- Write a custom React hook that debounces a value, and use it to search an API without race conditions.
- Explain React concept: controlled vs uncontrolled inputs.
- Explain React concept: JSX.
- What does `useState` do and when should you use it?