diff --git a/packages/stores/src/store.rs b/packages/stores/src/store.rs index cfc420ed54..ed1a5b6865 100644 --- a/packages/stores/src/store.rs +++ b/packages/stores/src/store.rs @@ -8,8 +8,8 @@ use dioxus_core::{ use dioxus_signals::{ read_impls, write_impls, BorrowError, BorrowMutError, BoxedSignalStorage, CopyValue, CreateBoxedSignalStorage, Global, InitializeFromFunction, MappedMutSignal, ReadSignal, - Readable, ReadableExt, ReadableRef, Storage, UnsyncStorage, Writable, WritableExt, WritableRef, - WriteSignal, + Readable, ReadableExt, ReadableRef, Storage, SyncStorage, UnsyncStorage, Writable, WritableExt, + WritableRef, WriteSignal, }; use std::marker::PhantomData; @@ -27,6 +27,9 @@ pub type ReadStore = Store>; /// A type alias for a boxed writable-only store. pub type WriteStore = Store>; +/// A type alias for a store backed by SyncStorage. +pub type SyncStore = Store>; + /// Stores are a reactive type built for nested data structures. Each store will lazily create signals /// for each field/member of the data structure as needed. /// @@ -404,6 +407,14 @@ pub fn use_store(init: impl FnOnce() -> T) -> Store { use_hook(move || Store::new(init())) } +/// Create a new [`SyncStore`]. Stores are a reactive type built for nested data structures. +/// `SyncStore` is a Store backed by `SyncStorage`. +/// +/// Like [`use_store`], but produces `SyncStore` instead of `Store` +pub fn use_store_sync(init: impl FnOnce() -> T) -> SyncStore { + use_hook(|| Store::new_maybe_sync(init())) +} + /// A type alias for global stores /// /// # Example