Data Loading with Router Loaders
Learn how React Router's data APIs let route definitions fetch their own data before rendering, decoupling data loading from component lifecycle.
Newer React Router versions (v6.4+) introduced a data-loading API where a route definition can specify a loader function that fetches whatever data that route's component needs, run by the router *before* rendering the route, rather than the component itself triggering a fetch inside a useEffect after it mounts. The loaded data is then accessible inside the component via useLoaderData().
Router loaders are like a restaurant starting to prepare your dish the moment you're seated (navigation begins) rather than waiting until the waiter has fully walked away and you've had time to look at the menu (component mounted) before even telling the kitchen what you ordered.