smolter
API

useLoaderData

Read the active loader result.

Compatibility

ReactAvailable in this renderer's browser integration.
React SSRAvailable to this renderer's SSR integration; browser event handlers run after hydration.
PreactAvailable in this renderer's browser integration.
Preact SSRAvailable to this renderer's SSR integration; browser event handlers run after hydration.

Import from @kasperrt/smolter/react @kasperrt/smolter/preact

Signature

function useLoaderData<T = RouteModule>(
  route?: T & LoaderSource,
): LoaderData<T>;

Parameters

Optionally pass a typed route object, or specify typeof loader / typeof clientLoader as the generic.

Returns

Inferred handler data or undefined.

Usage

Import this API from one of the entry points listed above. Keep server and build helpers in their dedicated subpaths.

const data = useLoaderData<typeof clientLoader>();

return <p>{data?.title}</p>;

Behavior and edge cases

A route argument limits reads to that active path. The hook subscribes to the selected data; unrelated state changes do not force a data subscriber update. It does not start a request. A successful loader may itself return undefined.

View implementation ↗