PersistedOptions
Says where persisted() stores its value and the schema a stored value must still match.
Usage
Persist a preference
This type is used by persisted
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>
);
}Type declaration
export interface PersistedOptions<T> {
/** The storage key the value lives under, as JSON. */
key: string;
/** What a stored value must be: anything else is a warning, and `initial`. */
schema: Schema<T>;
/** In the keychain, through secureStore, for small secrets. Its first read is asynchronous. */
secure?: boolean;
}Members 3
| Name | Type | Required | Description |
|---|---|---|---|
key | string | Yes | The storage key the value lives under, as JSON. |
schema | Schema<T> | Yes | What a stored value must be: anything else is a warning, and initial. |
secure | boolean | No | In the keychain, through secureStore, for small secrets. Its first read is asynchronous. |
Generated from the public TypeScript declarations: signatures, props and defaults come from the checked source, descriptions from its JSDoc. No defaults are invented.