useRevalidator
Revalidate the data on the page for reasons outside of normal data mutations like window focus or polling on an interval.This hook only works in Data and Framework modes.
Page data is already revalidated automatically after actions. If you find yourself using this for normal CRUD operations, you’re probably not taking advantage of
Form, useFetcher, or useSubmit that do this automatically.Signature
Parameters
None.Returns
object
An object with the following properties:
Usage
Revalidate on window focus
Revalidate on interval
Manual refresh button
Revalidate on visibility change
Revalidate on network status
Common Patterns
Window focus revalidation utility
Polling with cleanup
Smart revalidation
Revalidate with loading state
Conditional revalidation
Global revalidation component
Revalidate after mutation
If you’re revalidating after a mutation, consider using
Form, useFetcher, or useSubmit instead, which handle revalidation automatically.Important Notes
Automatic revalidation
React Router automatically revalidates data in these cases:- After an
actionis called from a<Form>,useFetcher, oruseSubmit - When URL params change
- When search params change for routes with
shouldRevalidatereturningtrue
When to use
UseuseRevalidator for:
- Window focus revalidation
- Polling/interval updates
- WebSocket message handlers
- Manual refresh buttons
- Network status changes
- Normal form submissions (use
<Form>instead) - CRUD operations (use
useFetcheroruseSubmit) - Navigation (data loads automatically)
Performance
Revalidation calls all active route loaders. For partial updates, consider usinguseFetcher to load specific routes.
Related
loader- Define route loadershouldRevalidate- Control automatic revalidationuseFetcher- Load data without navigationuseNavigation- Track navigation state