Find bugs and slow renders in a React app
I was asked this
No reports yet. Sign in to say where you were asked it.
A coding interview question asked in Meta's technical phone screen, last asked Aug 2025. It tests react, frontend and performance.
You get a small React app that works but has several bugs and performance problems. Find and fix them: unnecessary re-renders, event listeners that leak, and parts that render in the wrong place or at the wrong time. Explain how you found each one and why the fix works. Then say how you would speed up a component that is badly laggy.
Interface
Unless you agree on a different code base with the interviewer, assume a component like this one:
function Dashboard({ items }) {
const [width, setWidth] = useState(window.innerWidth);
const [query, setQuery] = useState("");
useEffect(() => {
window.addEventListener("resize", () => setWidth(window.innerWidth));
});
const filtered = items.filter(i => i.name.includes(query));
return (
<>
<input value={query} onChange={e => setQuery(e.target.value)} />
<Chart options={{ width }} />
{filtered.map((item, i) => <Row key={i} item={item} onSelect={() => select(item.id)} />)}
</>
);
}
Example
Some problems to find in this code:
useEffect with no dependency array and no cleanup -> a new resize listener on every render, never removed
key={i} on a filtered list -> rows keep the wrong state when the filter changes
options={{ width }} and inline onSelect -> new objects every render, so memoized children re-render anyway
filtering a large list on every keystroke -> typing lags
Constraints
- React 18 function components and hooks. Use the browser's devtools and the React Profiler.
Clarifying questions
- Which interactions feel slow, and on what devices?
- How large are the lists?
- Can I change the props or the data shape, or only this component?
- Is there a state library or a server cache involved?
What a strong answer covers
- A method before fixes: reproduce, measure with the React Profiler and the Performance panel, find what renders and why, then fix one thing at a time and measure again.
- Effects with correct dependencies and a cleanup that removes the same listener function.
- Stable keys from the data, not the index.
-
useMemo,useCallbackandReact.memowhere props are recreated, and where memoization is not worth it. - Moving state down or splitting components, so a keystroke re-renders only what depends on it.
- For a laggy component: virtualize long lists, debounce or
useDeferredValuefor filtering, move heavy work off the render path, and avoid layout thrashing.
Follow-ups
- The list has 50,000 rows. What do you change?
- A child re-renders even though
React.memowraps it. How do you find out why? - How would you stop these problems from coming back (lint rules, profiling in CI)?
Where it's asked
- Meta · Technical phone screen · Last asked Aug 202545 min · Two coding problems in CoderPad, about 20 minutes each · Usually no AI; some newer screens are AI-assisted
What it tests
No official answer yet. Write yours on the right and run it.
Nothing published yet.
Sign in to submit your code; every attempt is kept here.
