Skip to main content

Loaders

Loaders provide data to route components before they render. They run on the server during SSR and on the client during client-side navigation.

Basic Loader

Loaders are async functions that return data for your route:
filename=app/routes/product.tsx

Using useLoaderData

Access loader data in your component with the useLoaderData hook:

Loader Arguments

Loaders receive an object with these properties:

Returning Responses

Loaders can return various types of data:

Plain Objects

Response Objects

Redirects

Error Responses

Parallel Data Loading

Loaders for all matching routes run in parallel:

TypeScript

Use the generated Route types for full type safety:

Accessing Parent Loader Data

Use useRouteLoaderData to access data from parent routes:
Route IDs are automatically created from the file path:

Error Handling

Handle loader errors with ErrorBoundary:

Client Loaders

Use clientLoader to load data only on the client:

Best Practices

Keep Loaders Fast

Return Only What You Need