Course contentsShow
← React
Lesson 1852 of 2,39643. RoutingFree lesson

Revalidation: Automatic Data Refreshing

How actions automatically trigger loaders to rerun, keeping your UI in sync after mutations.

Revalidation: Automatic Data Refreshing

You'll learn: How React Router automatically refreshes your data after mutations without manual refetch calls.

The Invisible Refresh Cycle

Remember when we covered useNavigation and how it tracks pending states? React Router does something even more powerful behind the scenes: after any action completes successfully, it automatically reruns all active loaders to refresh your UI with the latest data.

Think of it like a vending machine with a glass front. When you buy a snack (action), the machine automatically updates what you see through the glass (revalidation). You don't need to press a "refresh display" button — it just happens.

How It Works

When a <Form> submission or fetcher.submit() triggers an action:

  1. The action runs (mutation happens on server)
  2. Action completes successfully
  3. React Router automatically calls all loaders for currently rendered routes
  4. Components receive fresh data via useLoaderData()
  5. UI updates to reflect the mutation

This is why you don't need manual refetch() calls or cache invalidation with React Router — it's built into the framework.

The Sync Pattern

// Loader fetches current todos
export async function todosLoader() {
  return fetch('/api/todos').then(r => r.json());
}

// Action adds a new todo
export async function addTodoAction({ request }) {
  const formData = await request.formData();
  await fetch('/api/todos', { 
    method: 'POST', 
    body: JSON.stringify({ text: formData.get('text') })
  });
  return { ok: true };
  // todosLoader reruns automatically after this!
}

The moment your action returns, the loader refreshes — no coordination code needed.

Key Takeaway: React Router's data router automatically reruns loaders after actions complete, keeping your UI synchronized with server state without manual cache management.