All jobs / Frontend / web developer / React
Frontend / web developer interview question · 3–5 years
Optimistic create plus a refetch returns the old list without the item. What do you guard?
The strongest answer
Reconcile with the server using stable ids — don't assume refetch order — and keep the mutation response as the source when it arrives
Why it works
Caches lie when writes and reads race. Ids and mutation payloads are how you merge.
What a good answer covers
- Races need ids, not hope.
- Optimistic insert with a temp or real id.
- Merge on mutation response.
- Treat refetch as truth, not as 'older'.
Answers that fall short
- Close, but not the strongest: Always wait for refetch and skip optimistic updates
Waiting is consistent and slower — say so if the product prefers it. - Weak: Concat the item blindly and accept duplicates
Blind concat duplicates on a late refetch that finally includes the row. - Red flag: Drop the server result if it disagrees
Ignoring the server hides other people's writes.
Who gets asked this
More React questions
- A lazy route flashes a blank screen, then an error. How do you structure Suspense and error boundaries?
- What is JSX, and what does the browser actually receive?
- What is the difference between props and state?
- What does useState return, and why must you call the setter instead of assigning?
- Why does React warn about a missing key when you render a list?
- What is a controlled input?
- What is useEffect for?
- What happens if useEffect has an empty dependency array, and if it has none at all?