persisted
A signal whose value survives the app's restarts. Its first read is synchronous; each write lands at once in memory and on disk when the JS task ends, in one transaction with the task's other writes.
Verwendung
Persist a preference
import { Text, Toggle, VStack, persisted, type Schema } from 'kuito';
const booleanSchema: Schema<boolean> = {
'~standard': {
version: 1,
vendor: 'example',
validate: (value) =>
typeof value === 'boolean' ? { value } : { issues: [{ message: 'Expected boolean' }] },
},
};
export function Preferences() {
const wifiOnly = persisted(true, { key: 'downloads.wifiOnly', schema: booleanSchema });
return (
<VStack gap={12}>
<Toggle label="Download on Wi-Fi only" checked={wifiOnly} />
<Text>{wifiOnly.value ? 'Wi-Fi only' : 'Any connection'}</Text>
</VStack>
);
}Signaturen
<T>(initial: T, options: PersistedOptions<T>): Signal<T>Typparameter
| Name | Einschränkung | Standard |
|---|---|---|
T | — | — |
Parameter
| Name | Typ | Erforderlich | Beschreibung |
|---|---|---|---|
initial | T | Ja | — |
options | PersistedOptions<T> | Ja | — |
Rückgabe
Signal<T>
Generiert aus den öffentlichen TypeScript-Deklarationen: Signaturen, Props und Standardwerte stammen aus der geprüften Quelle, Beschreibungen aus deren JSDoc. Kein Standardwert ist erfunden.