Skip to main content

useLoaderData

Returns the data from the closest route loader 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 return Response objects from loaders:

Client loaders

Access data from clientLoader:

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:
Use useNavigation for global loading UI.

Error handling

Throw errors in loaders to render the ErrorBoundary:

Parallel data loading

Load multiple resources in parallel:

Deferred data

Defer slow data loading:

Type Safety

SerializeFrom

The SerializeFrom type ensures data is JSON-serializable: