QueryOptions
stableQuery configuration options
Configuration interface for query options. Defines all available options for customizing query behavior including fetching, caching, and error handling.
Configuration Flexibility
QueryOptions provides extensive configuration options to customize query behavior for different use cases and scenarios.
Performance Impact
Be mindful of configuration choices that can impact performance, such as staleTime, and refetchOnSubscribe.
Signature
interface QueryOptions<TData, TError = Error> {fetcher?: () => Promise<TData>;staleTime?: number;refetchOnSubscribe?: 'always' | 'stale' | false;}
Parameters
fetcher
() => Promise<TData>Function that returns a Promise resolving to the data. Optional if fetcher was already registered.
staleTime
numberDefault: 0Time in milliseconds after which data is considered stale.
refetchOnSubscribe
'always' | 'stale' | falseDefault: 'stale'When to refetch data when component subscribes.
Behavior
Configurable
Highly configurable with many options for customization
Type Safe
Full TypeScript support with proper type inference
Flexible
Supports various use cases and scenarios
Extensible
Easy to extend with additional options
Best Practices
Do's
- ✓Use appropriate staleTime for your data freshness requirements
- ✓Configure retry logic for network resilience
- ✓Use callbacks for side effects and logging
- ✓Set refetchOnSubscribe based on your use case
Don'ts
- ✗Don't set staleTime too high for frequently changing data
- ✗Don't use too many retries for non-critical data
- ✗Don't forget to handle errors in onError callbacks
- ✗Don't use callbacks for state management