Expand description
§Dioxus Storage
Unified storage API for Dioxus applications.
Supports:
- IndexedDB - Large structured data, async, multiple stores
- LocalStorage - Simple key-value, synchronous, persistent
- SessionStorage - Key-value, per-session
§Example
ⓘ
use dioxus_storage::prelude::*;
use serde::{Serialize, Deserialize};
#[derive(Debug, Clone, Serialize, Deserialize)]
struct AppState {
theme: String,
user_id: Option<String>,
}
#[component]
fn App() -> Element {
// Use local storage for simple settings
let theme = use_local_storage::<String>("theme", "light".to_string());
// Use IndexedDB for structured data
let db = use_storage_db(
DatabaseConfig::new("my_app", 1)
.with_store("items", "id")
);
rsx! {
button {
onclick: move |_| {
theme.set("dark".to_string());
},
"Switch to Dark Mode"
}
}
}