Skip to content

ferreira-tb/tauri-store

Repository files navigation

tauri-store

Persistent stores for Tauri.

Features

  • Save your stores to disk.
  • Synchronize across multiple windows.
  • Debounce or throttle store updates.
  • Access the stores from both JavaScript and Rust.

Usage

import { Store } from 'tauri-store';

const store = new Store('my-store', { counter: 0 });

// Get a value. This is a synchronous operation!
const counter = store.get('counter');
console.log(counter);

// Set a value.
store.set('counter', 42);

// Update a value with a callback.
store.update('counter', (value) => value + 1);

// Set multiple values at once.
store.patch({ counter: 0 });

// Listen to changes.
store.subscribe((state) => {
  console.log(state);
});

// Save the store. Unlike the others, this is asynchronous.
await store.save();

Tip

There are also custom plugins that tightly integrate with your favorite framework or library.

Documentation

Check the documentation for more information on how to install and use the plugins.

Plugins

Currently, the following plugins are available:

Name Version Works with
tauri-store npm Everything
@tauri-store/pinia npm Vue, Nuxt
@tauri-store/svelte npm Svelte
@tauri-store/valtio npm React
@tauri-store/zustand npm React

Examples

You can find example projects in the examples directory. To check them out, run the following commands:

git clone https://github.com/ferreira-tb/tauri-store.git
cd tauri-store
pnpm install
pnpm run example [EXAMPLE_NAME]

For example, to run the pinia project, you can use:

pnpm run example pinia

For a completely random example, run:

pnpm run example random

Supported Tauri Version

The plugins require Tauri 2.0 or later.