Resource
Data a component loads when it mounts, read through signals, and loaded again on refresh().
Usage
Reveal a profile after its resource settles
This type is used by resource
import { Catch, Loading, Spinner, Text, resource } from 'kuito';
function Profile() {
const profile = resource(async ({ signal }) => {
const response = await fetch('https://example.com/api/profile', { signal });
if (!response.ok) throw new Error(`HTTP ${response.status}`);
return (await response.json()) as { name: string };
});
return <Text>{profile.data.value?.name ?? ''}</Text>;
}
export function Account() {
return (
<Catch fallback={<Text>Profile unavailable</Text>}>
<Loading fallback={<Spinner />}>
<Profile />
</Loading>
</Catch>
);
}Type declaration
export interface Resource<T> extends Task<[], T> {
refresh(): Promise<T>;
}Members 6
| Name | Type | Required | Description |
|---|---|---|---|
refresh | () => Promise<T> | Yes | — |
runningreadonly | ReadonlySignal<boolean> | Yes | — |
datareadonly | ReadonlySignal<T> | Yes | — |
errorreadonly | ReadonlySignal<unknown> | Yes | — |
run | () => Promise<T> | Yes | — |
cancel | (reason?: unknown) => void | Yes | — |
refresh — method signatures
Signatures
(): Promise<T>Parameters
No parameters.
Returns
Promise<T>
run — method signatures
Signatures
(): Promise<T>Parameters
| Name | Type | Required | Description |
|---|---|---|---|
...args | [] | Yes | — |
Returns
Promise<T>
cancel — method signatures
Signatures
(reason?: unknown): voidParameters
| Name | Type | Required | Description |
|---|---|---|---|
reason | unknown | No | — |
Returns
void
Generated from the public TypeScript declarations: signatures, props and defaults come from the checked source, descriptions from its JSDoc. No defaults are invented.