useLoaderData
Returns the data from the closest routeloader or clientLoader.
This hook only works in Data and Framework modes.
Signature
Parameters
None.Returns
SerializeFrom<T>
The data returned from the route’s
loader or clientLoader function. The type is automatically serialized for server loaders.Usage
Basic usage
With TypeScript (Framework mode)
In Framework mode, types are automatically generated:With TypeScript (Data mode)
In Data mode, manually type the hook:Return Response objects
You can returnResponse objects from loaders:
Client loaders
Access data fromclientLoader:
With route params
With request data
Common Patterns
Loading state
Loaders are called before the component renders, so there’s no loading state in the component:useNavigation for global loading UI.
Error handling
Throw errors in loaders to render theErrorBoundary:
Parallel data loading
Load multiple resources in parallel:Deferred data
Defer slow data loading:Type Safety
SerializeFrom
TheSerializeFrom type ensures data is JSON-serializable:
Related
loader- Define route loaderclientLoader- Client-only loaderuseRouteLoaderData- Access parent route datauseActionData- Access action datauseNavigation- Track loading state