React Native · APIs and utilities
Storage
Key-value store.
Import
Storage
classKey-value store. Reads and writes are synchronous: values are kept in memory and writes are appended to disk in the background. See createStorage.
createStorage
functionOpens a store (a second call with the same name returns the same object).
Examples
storage
constantThe default store (createStorage()); opened on first use.
deleteStorage
functionDeletes the store and its file (sign out).
useStorage
functionUses a value in the store like state: the component re-renders when it changes (even if written elsewhere), and writes persist.
Examples
StorageJson
typeA value that can be stored as JSON.
StorageValue
typeA value that can be stored: string, number, boolean, null or a JSON object/array.
StorageOptions
interfacecreateStorage options.
| Name | Type | Default | Description |
|---|---|---|---|
id? | string | "default" | Store name; stores opened with the same name are the same. Letters, digits, ., -, _. |
encrypted? | boolean | false | Encrypted store: records are encrypted with AES-256-GCM; the key is kept in the Android Keystore / iOS Keychain and never leaves the device. Read/write speed is almost the same. Encrypted and unencrypted stores with the same name are separate files. |
StorageSetOptions
interfaceStorage.set options.
| Name | Type | Description |
|---|---|---|
ttl? | number | Duration (ms): afterwards the value behaves as missing and is deleted (for caches). |
StorageListener
typeChange listener; key is null when the store was cleared.
AsyncStorageLike
interfaceSame interface as AsyncStorage (for libraries that expect it).
| Name | Type | Description |
|---|---|---|
getItem | (key: string): Promise<string | null> | Reads a value; null if missing. |
setItem | (key: string, value: string): Promise<void> | Writes a value. |
removeItem | (key: string): Promise<void> | Removes a value. |
mergeItem | (key: string, value: string): Promise<void> | Merges a JSON value into the existing one. |
getAllKeys | (): Promise<string[]> | All keys. |
clear | (): Promise<void> | Removes everything. |
multiGet | (keys: readonly string[]): Promise<[string, string | null][]> | Reads several values at once. |
multiSet | (pairs: readonly (readonly [string, string])[]): Promise<void> | Writes several values at once. |
multiRemove | (keys: readonly string[]): Promise<void> | Removes several values at once. |