Skip to main content

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 action is called from a <Form>, useFetcher, or useSubmit
  • When URL params change
  • When search params change for routes with shouldRevalidate returning true

When to use

Use useRevalidator for:
  • Window focus revalidation
  • Polling/interval updates
  • WebSocket message handlers
  • Manual refresh buttons
  • Network status changes
Don’t use for:
  • Normal form submissions (use <Form> instead)
  • CRUD operations (use useFetcher or useSubmit)
  • Navigation (data loads automatically)

Performance

Revalidation calls all active route loaders. For partial updates, consider using useFetcher to load specific routes.