> Tauri State & Events

Manage shared state and bidirectional events between Rust and frontend in Tauri apps.

fetch
$curl "https://skillshub.wtf/skillshub-team/catalog-batch5/tauri-state-events?format=md"
SKILL.mdTauri State & Events

Tauri State & Events

Shared State

use std::sync::Mutex;
use tauri::State;

struct AppState { counter: Mutex<i32> }

#[tauri::command]
fn increment(state: State<AppState>) -> i32 {
    let mut c = state.counter.lock().unwrap();
    *c += 1; *c
}

// Register: .manage(AppState { counter: Mutex::new(0) })

Events (Rust → Frontend)

use tauri::{AppHandle, Emitter};
#[tauri::command]
async fn long_task(app: AppHandle) {
    for i in 0..100 {
        app.emit("progress", i).unwrap();
        tokio::time::sleep(std::time::Duration::from_millis(50)).await;
    }
}
import { listen } from "@tauri-apps/api/event";
await listen<number>("progress", (e) => console.log(e.payload));

Error Handling

#[tauri::command]
fn risky_op() -> Result<String, String> {
    Err("Something failed".into()) // Reaches frontend as error
}

┌ stats

installs/wk0
░░░░░░░░░░
first seenMar 18, 2026
└────────────

┌ tags

└────────────