@zubridge/tauri
v1.1.0
Published
A streamlined state management library for Tauri applications using Zustand.
Downloads
214
Maintainers
Readme
Cross-platform state without boundaries: Zustand-inspired simplicity for Tauri
Why Zubridge?
tldr: I want to seamlessly interact with my Rust backend state using Zustand-inspired hooks.
Zustand provides a simple and effective state management pattern. In Tauri applications, managing state consistently between the Rust backend (where the authoritative state often resides) and multiple frontend windows can be complex.
Zubridge @zubridge/tauri simplifies this by providing hooks (useZubridgeStore, useZubridgeDispatch) that connect your frontend components to your Rust backend state, abstracting away the necessary Tauri command invocations and event listening.
How It Works
Zubridge creates a bridge between your Rust backend state and your frontend JavaScript. Your Rust backend holds the source of truth, while the frontend uses hooks to access and update this state.
- Backend: Register the
tauri-plugin-zubridgeplugin with your app state - Backend: Implement the
StateManagertrait to handle state changes - Frontend: Initialize the bridge with
@zubridge/tauri - Frontend: Access state with
useZubridgeStoreand dispatch actions withuseZubridgeDispatch
Features
- Simple State Management: Connect frontend components to Rust backend state using Zustand-like hooks
- Standard Interface: Consistent pattern for dispatching actions and receiving updates
- Type Safety: Strong typing for both Rust and TypeScript sides
- Multi-Window Support: Automatic state synchronization across multiple windows
- Minimal Boilerplate: Reduced code for state management through the official plugin
- Frontend Flexibility: Works with React, other frontend frameworks, or vanilla JavaScript
- Tauri Version Support: Compatible with both Tauri v1 and v2 APIs via dependency injection
Installation
Rust Backend
# Cargo.toml
[dependencies]
tauri-plugin-zubridge = "0.1.0"
serde = { version = "1.0", features = ["derive"] }Frontend
# Using npm
npm install @zubridge/tauri @tauri-apps/apiOr use your dependency manager of choice, e.g. pnpm, yarn.
Quick Start
- Define your application state and implement the
StateManagertrait in your Rust backend - Register the
tauri-plugin-zubridgeplugin in your Tauri application - Initialize the bridge in your frontend with
initializeBridge({ invoke, listen }) - Access state with
useZubridgeStoreand dispatch actions withuseZubridgeDispatch
For detailed implementation examples, see our Getting Started Guide.
Documentation
For more detailed documentation, see:
Example Applications
Complete example applications demonstrating the use of @zubridge/tauri:
Direct Architecture
Plugin Architecture
License
MIT
