All jobs / Frontend / web developer / React
Frontend / web developer interview question · 3–5 years
A like button uses optimistic UI. The request fails. What must happen?
The strongest answer
Roll back local state and the cache, show the error, and leave the action retryable
Why it works
Optimistic UI is a loan: failure must repay it. Users should see the truth and be able to try again.
What a good answer covers
- Optimism needs a rollback.
- Apply the local like.
- On error, revert cache and UI.
- Tell the user; allow retry.
Answers that fall short
- Close, but not the strongest: Leave the like on and hope the next refresh agrees
Hope is a desync. - Weak: Reload the page
A full reload is a blunt rollback. - Red flag: Retry silently forever
Silent infinite retry can amplify an outage.
Who gets asked this
More React questions
- Optimistic create plus a refetch returns the old list without the item. What do you guard?
- 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?