resource
Loads data for a component once it has mounted, with its progress, result and error as signals and refresh() to load it again.
Verwendung
Reveal a profile after its resource settles
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>
);
}Signaturen
Generiert aus den öffentlichen TypeScript-Deklarationen: Signaturen, Props und Standardwerte stammen aus der geprüften Quelle, Beschreibungen aus deren JSDoc. Kein Standardwert ist erfunden.