What is optimistic UI and how can you build it?

React data fetching and state libraries · Freshers and experienced

Model answer

Optimistic UI updates the screen immediately as if the server request will succeed, then fixes it if it fails. For example, a like button turns on at once. With TanStack Query you update the cache in onMutate and roll back in onError. React 19 offers useOptimistic for the same idea.

Always handle the failure case so users see the true state.

Learn this topic

TanStack Query (React Query): Fetching, Caching and Updating Server Data in the course React.js Full Course: Beginner to Advanced.

Sign in to add your own answer.

More questions