One Logo Pool Ball
wwwwwwwwwwwwwwwwwww

useLoader

Returns the data from a route loader. The loader must be defined in the same file as the component using it.

Basic Usage

import { useLoader } from 'one'
export function loader() {
return { hello: 'world' }
}
export default function Page() {
const data = useLoader(loader)
return (
<>{data.hello}</>
)
}

Automatic Refetching

Loaders automatically refetch when:

When to Use

Use useLoader when:

For more advanced use cases like manual refetching, loading states, or accessing refetch from child components, see useLoaderState.

TypeScript

The hook is fully typed based on your loader’s return type:

export function loader() {
return {
user: { id: 1, name: 'John' },
posts: [] as Post[]
}
}
export default function Page() {
const data = useLoader(loader)
// TypeScript knows: data.user.name is string
// TypeScript knows: data.posts is Post[]
}

Edit this page on GitHub.