Skip to main content

Optimistic UI

Optimistic UI updates the interface immediately when a user takes an action, before waiting for the server response. This creates a faster, more responsive user experience.

Basic Concept

Instead of waiting for the server:

Using useFetcher

The most common way to implement optimistic UI:

Optimistic Lists

Add items to lists immediately:

Optimistic Updates

Update items immediately:

Optimistic Deletes

Remove items immediately:

Using useFetchers

Track multiple fetchers for complex UIs:

Multiple Operations

Handle different intents:

Error Handling

Show errors and restore original state:

Loading States

Provide visual feedback:

Revalidation

Combine optimistic updates with revalidation:

Complex Example: Shopping Cart

Best Practices

Mark Pending Items

Provide Immediate Feedback

Handle Errors Gracefully