Documentation Index
Fetch the complete documentation index at: https://mintlify.com/RtlZeroMemory/Rezi/llms.txt
Use this file to discover all available pages before exploring further.
Loading & Async State Patterns
Patterns for managing asynchronous data fetching, loading indicators, error handling, and retry logic.Problem
You need to:- Fetch data asynchronously (API calls, file I/O)
- Show loading indicators during async operations
- Handle and display errors gracefully
- Implement retry logic
- Prevent race conditions
- Show skeleton/placeholder UI
Solution
Model async state explicitly as a tagged union and render appropriate UI for each state.Basic Loading State Pattern
- Tagged union - Explicit state representation
- Exhaustive matching - TypeScript ensures all states handled
- Retry logic - Same function for initial load and retry
Loading Indicators
Spinner
Progress Bar
Skeleton Placeholders
Loading Overlay
Error Handling
Error Display Patterns
Empty State
Inline Errors
Async with useAsync Hook
For component-level async operations:useAsync features:
- Automatic state management -
isLoading,error,data - Dependency tracking - Refetch when dependencies change
- Retry support -
retry()method - Cleanup - Cancels on unmount
Preventing Race Conditions
Request Cancellation
Debounced Search
Optimistic Updates
Update UI immediately, rollback on error:Polling Pattern
Pagination with Loading
Best Practices
- Model loading state explicitly - Use tagged unions (
idle | loading | success | error) - Always handle all states - Exhaustive matching ensures no missing cases
- Use skeletons for predictable content - Show layout structure while loading
- Provide retry logic - Always offer a way to retry failed requests
- Show progress for long operations - Use
ui.progress()for determinate progress - Prevent race conditions - Use request IDs or AbortController
- Debounce user input - Reduce unnecessary API calls
- Cancel on unmount - Clean up ongoing requests
- Optimistic updates for better UX - Update UI immediately, rollback on error
- Show empty states - Guide users when no data is available
Related
- Spinner Widget - Loading indicators
- Progress Widget - Progress bars
- Skeleton Widget - Placeholder content
- Empty Widget - Empty and error states
- Callout Widget - Error messages
- Forms Recipe - Form submission patterns