Persist App State to Disk in Tauri 2 | Store Plugin Tutorial
About this lesson
Make your Tauri 2 app remember things across restarts. tauri-plugin-store gives you a tiny key-value store that writes JSON to the OS app data directory — no schema, no migrations, no boilerplate. Set a value, restart the app, the value is still there. Source code: https://github.com/GoCelesteAI/tauri_persisto We build Persisto, a minimal counter that survives every relaunch: increment, decrement, reset — quit the app, reopen it, the count is exactly where you left it. The whole thing is one App.tsx, one Rust plugin registration, one capability entry. What You'll Learn: - tauri-plugin-store — install on both the Rust side (Cargo) and the JS side (pnpm) and register the plugin in lib.rs. - load("counter.json", { autoSave: true }) — opens (or creates) the store file at the platform-correct path. autoSave writes through on every change so you don't have to call save() manually. - store.set(key, value) and typed store.get — typed key-value reads and writes. Values are JSON, so any serializable type works. - The platform store path — macOS Application Support, Linux ~/.local/share, Windows %APPDATA% — each scoped to your bundle identifier. Tauri resolves it from the identifier in tauri.conf.json. - Capability gating — store:default is the permission your capabilities/default.json needs. Without it, the JS load() call errors at runtime. - The load-then-render pattern — call load() once in useEffect, seed React state from store.get, and write back on every change. Pattern works for any "remember the last X" requirement. Timestamps: 0:00 - The proof: increment, quit, relaunch, still there 0:25 - Capability config — store:default 0:50 - Register tauri-plugin-store in lib.rs 1:20 - App.tsx — load the store, read on mount, write on change 3:30 - Run it — the counter that survives restarts 4:15 - End screen Key Takeaways: 1. tauri-plugin-store is the right default for app state. For settings, preferences, last-opened-file paths, window geometry, anything that fits in a fl
DeepCamp AI