Utilisation

Persist a preference

Ce type est utilisé par persisted

tsx
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>
  );
}

Déclaration du type

ts
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;
}

Membres 3

NomTypeRequisDescription
keystringOuiThe storage key the value lives under, as JSON.
schemaSchema<T>OuiWhat a stored value must be: anything else is a warning, and initial.
securebooleanNonIn the keychain, through secureStore, for small secrets. Its first read is asynchronous.
Généré depuis les déclarations TypeScript publiques : signatures, props et valeurs par défaut viennent de la source vérifiée, les descriptions de sa JSDoc. Aucune valeur par défaut n'est inventée.