Skip to main content

dioxus_client_storage/
lib.rs

1//! # Dioxus Storage
2//!
3//! Unified storage API for Dioxus applications.
4//!
5//! Supports:
6//! - **IndexedDB** - Large structured data, async, multiple stores
7//! - **LocalStorage** - Simple key-value, synchronous, persistent
8//! - **SessionStorage** - Key-value, per-session
9//!
10//! ## Example
11//!
12//! ```rust,ignore
13//! use dioxus_storage::prelude::*;
14//! use serde::{Serialize, Deserialize};
15//!
16//! #[derive(Debug, Clone, Serialize, Deserialize)]
17//! struct AppState {
18//!     theme: String,
19//!     user_id: Option<String>,
20//! }
21//!
22//! #[component]
23//! fn App() -> Element {
24//!     // Use local storage for simple settings
25//!     let theme = use_local_storage::<String>("theme", "light".to_string());
26//!     
27//!     // Use IndexedDB for structured data
28//!     let db = use_storage_db(
29//!         DatabaseConfig::new("my_app", 1)
30//!             .with_store("items", "id")
31//!     );
32//!     
33//!     rsx! {
34//!         button {
35//!             onclick: move |_| {
36//!                 theme.set("dark".to_string());
37//!             },
38//!             "Switch to Dark Mode"
39//!         }
40//!     }
41//! }
42//! ```
43
44#![cfg(target_arch = "wasm32")]
45
46mod error;
47mod local_storage;
48mod session_storage;
49mod storage;
50
51pub use error::{Result, StorageError};
52pub use local_storage::{use_local_storage, LocalStorage};
53pub use session_storage::{use_session_storage, SessionStorage};
54pub use storage::{use_storage, Storage, StorageConfig};
55
56#[cfg(feature = "indexeddb")]
57pub use dioxus_indexeddb::{Collection, Database, DatabaseConfig as DbConfig};
58
59/// Prelude module for convenient imports
60pub mod prelude {
61    pub use super::{use_local_storage, LocalStorage};
62    pub use super::{use_session_storage, SessionStorage};
63    pub use super::{use_storage, Storage, StorageConfig};
64    pub use super::{Result, StorageError};
65
66    #[cfg(feature = "indexeddb")]
67    pub use super::{Collection, Database, DbConfig};
68}
69
70// Re-export indexeddb types when feature is enabled
71#[cfg(feature = "indexeddb")]
72pub mod indexeddb {
73    pub use dioxus_indexeddb::*;
74}