Skip to content

Getting started

Supported Tauri Version

This plugin requires Tauri 2.0 or later.

Install

Install the Rust crate by adding the following to your Cargo.toml file:

toml
[dependencies]
tauri-store = "0.10"

Install the JavaScript package with your preferred package manager:

shell
npm install tauri-store
shell
pnpm add tauri-store
shell
deno add npm:tauri-store
shell
bun add tauri-store
shell
yarn add tauri-store

Usage

  1. Enable the required permissions in your capabilities file:
json
{
  "identifier": "tauri-store",
  "windows": ["*"],
  "permissions": ["tauri-store:default", "core:event:default"]
}
  1. Register the plugin with Tauri:
rust
tauri::Builder::default()
  .plugin(tauri_store::init())
  .run(tauri::generate_context!())
  .expect("error while running tauri application");
  1. Create a store:
typescript
import { Store } from 'tauri-store';

const store = new Store('counter', { counter: 0 });
  1. Start it:
typescript
await store.start();

TIP

Stores won't be saved nor synchronized until you call the start method.

  1. Use the store:
typescript
// 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();