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

The Data Router Paradigm Shift in v6.4

Understanding how loaders and actions move data fetching from components to routes, enabling better UX patterns.

The Data Router Paradigm Shift in v6.4

You'll learn: How React Router v6.4 fundamentally changed where data fetching happens, moving it from components to route definitions.

The Old Way vs The New Way

Before v6.4, data fetching lived inside components. You'd render a component, it would fetch data in a useEffect, show a loading spinner, then display content. This created waterfalls: route matches → component renders → fetch starts → data arrives → content shows.

React Router v6.4 introduced data routers with a radical shift: data fetching happens at the route level using loader functions. When navigation begins, loaders run before components render. The router waits for data, then renders your component with everything ready.

How Loaders Change Everything

A loader is a function you attach to a route definition. It runs during navigation, fetches data, and returns it. Your component receives this data through the useLoaderData() hook—no useEffect, no loading states in the component itself.

Think of it like a restaurant: the old way was ordering food after you sit down (component mounts). The new way is pre-ordering—your food arrives when you sit down (component renders).

Actions: The Write Side

Similarly, actions handle data mutations at the route level. Form submissions trigger actions before navigation completes. After an action succeeds, loaders automatically rerun to refresh data—no manual cache invalidation needed.

This pattern enables optimistic UI, better loading states (handled by the router), and simpler components that just render data instead of orchestrating fetches.

Key Takeaway: Data routers move fetching from useEffect in components to loader functions on routes, eliminating waterfalls and enabling router-managed loading states, while action functions handle mutations and trigger automatic revalidation.