Skip to content

@tauri-apps/plugin-store

Simple, persistent key-value store.

A store is persisted to a file inside the application data directory and is shared with the Rust side of the application, which can read and write the same store through its own API.

function getStore(path: string): Promise<Store | null>;

Defined in: plugins/store/guest-js/index.ts:100

Gets an already loaded store.

If the store is not loaded, returns null. In this case you must load it.

This function is more useful when you already know the store is loaded and just need to access its instance. Prefer Store.load otherwise.

import { getStore } from '@tauri-apps/plugin-store';
const store = await getStore('store.json');
Parameter Type Description
path string Path of the store.

Promise<Store | null>

A promise resolving to the store instance, or null if it is not loaded.

2.1.0


function load(path: string, options?: StoreOptions): Promise<Store>;

Defined in: plugins/store/guest-js/index.ts:74

Create a new Store or load the existing store with the path.

If the file at the given path does not exist yet, the store is created in memory with the configured defaults and the file is only written on the first save.

import { load } from '@tauri-apps/plugin-store';
const store = await load('store.json');
Parameter Type Description
path string Path to save the store in app_data_dir
options? StoreOptions Store configuration options

Promise<Store>

A promise resolving to the loaded store.

2.1.0

Defined in: plugins/store/guest-js/index.ts:112

A lazy loaded key-value store persisted by the backend layer.

The underlying Store is only created or loaded when one of the methods of this class is called for the first time, and every call afterwards reuses that same instance.

2.1.0

  • IStore

new LazyStore(path: string, options?: StoreOptions): LazyStore;

Defined in: plugins/store/guest-js/index.ts:136

Creates a handle to the store at the given path without loading it yet.

Note that the options are not applied if someone else already created the store

import { LazyStore } from '@tauri-apps/plugin-store';
const store = new LazyStore('store.json');
Parameter Type Description
path string Path to save the store in app_data_dir
options? StoreOptions Store configuration options

LazyStore

clear(): Promise<void>;

Defined in: plugins/store/guest-js/index.ts:244

Clears the store, removing all key-value pairs.

Note: To clear the storage and reset it to its default value, use reset instead. Delegates to Store.clear on the underlying store, loading it first if needed.

import { LazyStore } from '@tauri-apps/plugin-store';
const store = new LazyStore('store.json');
await store.clear();

Promise<void>

IStore.clear

close(): Promise<void>;

Defined in: plugins/store/guest-js/index.ts:433

Close the store and cleans up this resource from memory. You should not call any method on this object anymore and should drop any reference to it.

Delegates to Store.close on the underlying store. If the store was never loaded, this method does nothing.

import { LazyStore } from '@tauri-apps/plugin-store';
const store = new LazyStore('store.json');
await store.close();

Promise<void>

IStore.close

delete(key: string): Promise<boolean>;

Defined in: plugins/store/guest-js/index.ts:227

Removes a key-value pair from the store.

Delegates to Store.delete on the underlying store, loading it first if needed.

import { LazyStore } from '@tauri-apps/plugin-store';
const store = new LazyStore('store.json');
const removed = await store.delete('some-key');
Parameter Type Description
key string The key to remove.

Promise<boolean>

A promise resolving to true if the key existed and was removed.

IStore.delete

entries<T>(): Promise<[string, T][]>;

Defined in: plugins/store/guest-js/index.ts:315

Returns a list of all entries in the store.

Delegates to Store.entries on the underlying store, loading it first if needed.

import { LazyStore } from '@tauri-apps/plugin-store';
const store = new LazyStore('store.json');
const entries = await store.entries();
Type Parameter
T

Promise<[string, T][]>

A promise resolving to the list of key-value pairs, in arbitrary order.

IStore.entries

get<T>(key: string): Promise<T | undefined>;

Defined in: plugins/store/guest-js/index.ts:189

Returns the value for the given key or undefined if the key does not exist.

Delegates to Store.get on the underlying store, loading it first if needed.

import { LazyStore } from '@tauri-apps/plugin-store';
const store = new LazyStore('store.json');
const value = await store.get<{ value: number }>('some-key');
Type Parameter
T
Parameter Type Description
key string The key to read the value of.

Promise<T | undefined>

A promise resolving to the stored value, or undefined if the key does not exist.

IStore.get

has(key: string): Promise<boolean>;

Defined in: plugins/store/guest-js/index.ts:208

Returns true if the given key exists in the store.

Delegates to Store.has on the underlying store, loading it first if needed.

import { LazyStore } from '@tauri-apps/plugin-store';
const store = new LazyStore('store.json');
const exists = await store.has('some-key');
Parameter Type Description
key string The key to check.

Promise<boolean>

A promise resolving to true if the key exists in the store.

IStore.has

init(): Promise<void>;

Defined in: plugins/store/guest-js/index.ts:151

Init/load the store if it’s not loaded already

import { LazyStore } from '@tauri-apps/plugin-store';
const store = new LazyStore('store.json');
await store.init();

Promise<void>

keys(): Promise<string[]>;

Defined in: plugins/store/guest-js/index.ts:279

Returns a list of all keys in the store.

Delegates to Store.keys on the underlying store, loading it first if needed.

import { LazyStore } from '@tauri-apps/plugin-store';
const store = new LazyStore('store.json');
const keys = await store.keys();

Promise<string[]>

A promise resolving to the list of keys, in arbitrary order.

IStore.keys

length(): Promise<number>;

Defined in: plugins/store/guest-js/index.ts:333

Returns the number of key-value pairs in the store.

Delegates to Function.length on the underlying store, loading it first if needed.

import { LazyStore } from '@tauri-apps/plugin-store';
const store = new LazyStore('store.json');
const length = await store.length();

Promise<number>

A promise resolving to the number of key-value pairs in the store.

IStore.length

onChange<T>(cb: (key: string, value: T | undefined) => void): Promise<UnlistenFn>;

Defined in: plugins/store/guest-js/index.ts:413

Listen to changes on the store.

Delegates to Store.onChange on the underlying store, loading it first if needed.

import { LazyStore } from '@tauri-apps/plugin-store';
const store = new LazyStore('store.json');
const unlisten = await store.onChange<{ value: number }>((key, value) => {
console.log(key, value);
});
Type Parameter
T
Parameter Type Description
cb (key: string, value: T | undefined) => void Callback invoked with the changed key and its new value, which is undefined when the key was removed.

Promise<UnlistenFn>

A promise resolving to a function to unlisten to the event.

IStore.onChange

onKeyChange<T>(key: string, cb: (value: T | undefined) => void): Promise<UnlistenFn>;

Defined in: plugins/store/guest-js/index.ts:389

Listen to changes on a store key.

Delegates to Store.onKeyChange on the underlying store, loading it first if needed.

import { LazyStore } from '@tauri-apps/plugin-store';
const store = new LazyStore('store.json');
const unlisten = await store.onKeyChange<{ value: number }>('some-key', (value) => {
console.log(value);
});
Type Parameter
T
Parameter Type Description
key string The key to watch for changes.
cb (value: T | undefined) => void Callback invoked with the new value, or undefined when the key was removed.

Promise<UnlistenFn>

A promise resolving to a function to unlisten to the event.

IStore.onKeyChange

reload(options?: ReloadOptions): Promise<void>;

Defined in: plugins/store/guest-js/index.ts:351

Attempts to load the on-disk state at the store’s path into memory.

Delegates to Store.reload on the underlying store, loading it first if needed.

import { LazyStore } from '@tauri-apps/plugin-store';
const store = new LazyStore('store.json');
await store.reload({ ignoreDefaults: true });
Parameter Type Description
options? ReloadOptions Options to change how the on-disk state is merged into the store.

Promise<void>

IStore.reload

reset(): Promise<void>;

Defined in: plugins/store/guest-js/index.ts:261

Resets the store to its default value.

If no default value has been set, this method behaves identical to clear. Delegates to Store.reset on the underlying store, loading it first if needed.

import { LazyStore } from '@tauri-apps/plugin-store';
const store = new LazyStore('store.json', { defaults: { 'some-key': 0 } });
await store.reset();

Promise<void>

IStore.reset

save(): Promise<void>;

Defined in: plugins/store/guest-js/index.ts:367

Saves the store to disk at the store’s path.

Delegates to Store.save on the underlying store, loading it first if needed.

import { LazyStore } from '@tauri-apps/plugin-store';
const store = new LazyStore('store.json');
await store.save();

Promise<void>

IStore.save

set(key: string, value: unknown): Promise<void>;

Defined in: plugins/store/guest-js/index.ts:170

Inserts a key-value pair into the store, loading it first if needed.

Delegates to Store.set on the underlying store.

import { LazyStore } from '@tauri-apps/plugin-store';
const store = new LazyStore('store.json');
await store.set('some-key', { value: 5 });
Parameter Type Description
key string The key to insert the value at.
value unknown The value to store, which must be serializable to JSON.

Promise<void>

IStore.set

values<T>(): Promise<T[]>;

Defined in: plugins/store/guest-js/index.ts:297

Returns a list of all values in the store.

Delegates to Store.values on the underlying store, loading it first if needed.

import { LazyStore } from '@tauri-apps/plugin-store';
const store = new LazyStore('store.json');
const values = await store.values();
Type Parameter
T

Promise<T[]>

A promise resolving to the list of values, in arbitrary order.

IStore.values

Defined in: plugins/store/guest-js/index.ts:449

A key-value store persisted by the backend layer.

The values are kept in memory and written to the store’s file on Store.save, and automatically after every modification unless auto save is disabled with StoreOptions.autoSave.

2.0.0

  • Resource
  • IStore
[key: number]: () => Promise<void>

get rid(): number;

Defined in: @tauri-apps/api/core.d.ts:412

number

Resource.rid

clear(): Promise<void>;

Defined in: plugins/store/guest-js/index.ts:605

Clears the store, removing all key-value pairs.

Note: To clear the storage and reset it to its default value, use reset instead. A change event is emitted for every removed key.

import { Store } from '@tauri-apps/plugin-store';
const store = await Store.load('store.json');
await store.clear();

Promise<void>

IStore.clear

close(): Promise<void>;

Defined in: @tauri-apps/api/core.d.ts:421

Destroys and cleans up this resource from memory. You should not call any method on this object anymore and should drop any reference to it.

Promise<void>

Uses the core:resources:allow-close permission, which is part of the core:resources:default permission set enabled by default.

IStore.close
Resource.close

delete(key: string): Promise<boolean>;

Defined in: plugins/store/guest-js/index.ts:585

Removes a key-value pair from the store.

A change event is emitted when the key existed and, unless auto save is disabled, the store is scheduled to be written to disk.

import { Store } from '@tauri-apps/plugin-store';
const store = await Store.load('store.json');
const removed = await store.delete('some-key');
Parameter Type Description
key string The key to remove.

Promise<boolean>

A promise resolving to true if the key existed and was removed.

IStore.delete

entries<T>(): Promise<[string, T][]>;

Defined in: plugins/store/guest-js/index.ts:670

Returns a list of all entries in the store.

import { Store } from '@tauri-apps/plugin-store';
const store = await Store.load('store.json');
const entries = await store.entries();
Type Parameter
T

Promise<[string, T][]>

A promise resolving to the list of key-value pairs, in arbitrary order.

IStore.entries

get<T>(key: string): Promise<T | undefined>;

Defined in: plugins/store/guest-js/index.ts:541

Returns the value for the given key or undefined if the key does not exist.

import { Store } from '@tauri-apps/plugin-store';
const store = await Store.load('store.json');
const value = await store.get<{ value: number }>('some-key');
Type Parameter
T
Parameter Type Description
key string The key to read the value of.

Promise<T | undefined>

A promise resolving to the stored value, or undefined if the key does not exist.

IStore.get

has(key: string): Promise<boolean>;

Defined in: plugins/store/guest-js/index.ts:562

Returns true if the given key exists in the store.

import { Store } from '@tauri-apps/plugin-store';
const store = await Store.load('store.json');
const exists = await store.has('some-key');
Parameter Type Description
key string The key to check.

Promise<boolean>

A promise resolving to true if the key exists in the store.

IStore.has

keys(): Promise<string[]>;

Defined in: plugins/store/guest-js/index.ts:638

Returns a list of all keys in the store.

import { Store } from '@tauri-apps/plugin-store';
const store = await Store.load('store.json');
const keys = await store.keys();

Promise<string[]>

A promise resolving to the list of keys, in arbitrary order.

IStore.keys

length(): Promise<number>;

Defined in: plugins/store/guest-js/index.ts:686

Returns the number of key-value pairs in the store.

import { Store } from '@tauri-apps/plugin-store';
const store = await Store.load('store.json');
const length = await store.length();

Promise<number>

A promise resolving to the number of key-value pairs in the store.

IStore.length

onChange<T>(cb: (key: string, value: T | undefined) => void): Promise<UnlistenFn>;

Defined in: plugins/store/guest-js/index.ts:781

Listen to changes on the store.

The callback is only invoked for changes made to this store instance.

import { Store } from '@tauri-apps/plugin-store';
const store = await Store.load('store.json');
const unlisten = await store.onChange<{ value: number }>((key, value) => {
console.log(key, value);
});
Type Parameter
T
Parameter Type Description
cb (key: string, value: T | undefined) => void Callback invoked with the changed key and its new value, which is undefined when the key was removed.

Promise<UnlistenFn>

A promise resolving to a function to unlisten to the event.

2.0.0

IStore.onChange

onKeyChange<T>(key: string, cb: (value: T | undefined) => void): Promise<UnlistenFn>;

Defined in: plugins/store/guest-js/index.ts:751

Listen to changes on a store key.

The callback is only invoked for changes made to this store instance.

import { Store } from '@tauri-apps/plugin-store';
const store = await Store.load('store.json');
const unlisten = await store.onKeyChange<{ value: number }>('some-key', (value) => {
console.log(value);
});
Type Parameter
T
Parameter Type Description
key string The key to watch for changes.
cb (value: T | undefined) => void Callback invoked with the new value, or undefined when the key was removed.

Promise<UnlistenFn>

A promise resolving to a function to unlisten to the event.

2.0.0

IStore.onKeyChange

reload(options?: ReloadOptions): Promise<void>;

Defined in: plugins/store/guest-js/index.ts:710

Attempts to load the on-disk state at the store’s path into memory.

This method is useful if the on-disk state was edited by the user and you want to synchronize the changes.

Note:

  • This method loads the data and merges it with the current store, this behavior will be changed to resetting to default first and then merging with the on-disk state in v3, to fully match the store with the on-disk state, set ignoreDefaults to true
  • This method does not emit change events.
import { Store } from '@tauri-apps/plugin-store';
const store = await Store.load('store.json');
await store.reload({ ignoreDefaults: true });
Parameter Type Description
options? ReloadOptions Options to change how the on-disk state is merged into the store.

Promise<void>

IStore.reload

reset(): Promise<void>;

Defined in: plugins/store/guest-js/index.ts:622

Resets the store to its default value.

If no default value has been set, this method behaves identical to clear. A change event is emitted for every key whose value changed.

import { Store } from '@tauri-apps/plugin-store';
const store = await Store.load('store.json', { defaults: { 'some-key': 0 } });
await store.reset();

Promise<void>

IStore.reset

save(): Promise<void>;

Defined in: plugins/store/guest-js/index.ts:727

Saves the store to disk at the store’s path.

Any pending auto save is cancelled, so the store is written exactly once by this call.

import { Store } from '@tauri-apps/plugin-store';
const store = await Store.load('store.json', { autoSave: false });
await store.set('some-key', { value: 5 });
await store.save();

Promise<void>

IStore.save

set(key: string, value: unknown): Promise<void>;

Defined in: plugins/store/guest-js/index.ts:520

Inserts a key-value pair into the store.

A change event is emitted for the key and, unless auto save is disabled, the store is scheduled to be written to disk.

import { Store } from '@tauri-apps/plugin-store';
const store = await Store.load('store.json');
await store.set('some-key', { value: 5 });
Parameter Type Description
key string The key to insert the value at.
value unknown The value to store, which must be serializable to JSON.

Promise<void>

IStore.set

values<T>(): Promise<T[]>;

Defined in: plugins/store/guest-js/index.ts:654

Returns a list of all values in the store.

import { Store } from '@tauri-apps/plugin-store';
const store = await Store.load('store.json');
const values = await store.values();
Type Parameter
T

Promise<T[]>

A promise resolving to the list of values, in arbitrary order.

IStore.values

static get(path: string): Promise<Store | null>;

Defined in: plugins/store/guest-js/index.ts:498

Gets an already loaded store.

If the store is not loaded, returns null. In this case you must load it.

This function is more useful when you already know the store is loaded and just need to access its instance. Prefer Store.load otherwise.

import { Store } from '@tauri-apps/plugin-store';
let store = await Store.get('store.json');
if (!store) {
store = await Store.load('store.json');
}
Parameter Type Description
path string Path of the store.

Promise<Store | null>

A promise resolving to the store instance, or null if it is not loaded.

static load(path: string, options?: StoreOptions): Promise<Store>;

Defined in: plugins/store/guest-js/index.ts:470

Create a new Store or load the existing store with the path.

If the file at the given path does not exist yet, the store is created in memory with the configured defaults and the file is only written on the first save.

import { Store } from '@tauri-apps/plugin-store';
const store = await Store.load('store.json');
Parameter Type Description
path string Path to save the store in app_data_dir
options? StoreOptions Store configuration options

Promise<Store>

A promise resolving to the loaded store.

type ReloadOptions = {
ignoreDefaults?: boolean;
};

Defined in: plugins/store/guest-js/index.ts:928

Options to change how a store is reloaded from its on-disk state.

Property Type Description Defined in
ignoreDefaults? boolean To fully match the store with the on-disk state, ignoring defaults plugins/store/guest-js/index.ts:932

type StoreOptions = {
autoSave?: boolean | number;
createNew?: boolean;
defaults?: {
[key: string]: unknown;
};
deserializeFnName?: string;
overrideDefaults?: boolean;
serializeFnName?: string;
};

Defined in: plugins/store/guest-js/index.ts:29

Options to create a store

Property Type Description Defined in
autoSave? boolean | number Auto save on modification with debounce duration in milliseconds, it’s 100ms by default, pass in false to disable it plugins/store/guest-js/index.ts:37
createNew? boolean Force create a new store with default values even if it already exists. plugins/store/guest-js/index.ts:49
defaults? { [key: string]: unknown; } Default value of the store plugins/store/guest-js/index.ts:33
deserializeFnName? string Name of a deserialize function registered in the rust side plugin builder plugins/store/guest-js/index.ts:45
overrideDefaults? boolean When creating the store, override the store with the on-disk state if it exists, ignoring defaults plugins/store/guest-js/index.ts:53
serializeFnName? string Name of a serialize function registered in the rust side plugin builder plugins/store/guest-js/index.ts:41

© 2026 Tauri Contributors. CC-BY / MIT