State Management · Senior · Question 42 of 75
How do you build optimistic UI with a React Router fetcher?
- ✓Correct answer: Render from
fetcher.formDatawhilefetcher.state !== 'idle', falling back to loader data - 2Update a global store first and then call the action
- 3Optimistic UI isn't possible with loaders and actions
Explanation
The submitted values are available immediately: const done = fetcher.formData ? fetcher.formData.get('done') === 'true' : todo.done. After the action completes and loaders revalidate, the real data takes over.