useOptimisticState
Show the result of an update immediately, run the real request, and roll back if it fails. Works on React 18 without useOptimistic.
- Level
- Advanced
- Since
- v2.1.0
import {useOptimisticState} from '@zenuilabs/react-hooks';Loading demo_
More in Async & Data
Async & DataIntermediateuseAsyncRun an async function and track its loading, error and data. Only the most recent call updates state, so a slow earlier call never overwrites a newer result.Async & DataIntermediateuseAsyncRetryRun an async function and retry it when it fails, with a fixed delay or backoff. Use it for flaky network calls that usually succeed on a second try.Async & DataAdvanceduseCachedFetchStale-while-revalidate data fetching with a cache shared by every component. Cached data renders instantly while a background request refreshes it.