@multiplatform.one/store
v6.7.0
Published
multiplatform.one TanStack Store with cross-platform persistent storage
Downloads
123
Readme
@multiplatform.one/store
TanStack Store state management with cross-platform persistent storage (localStorage on web, AsyncStorage-style on native) for multiplatform.one.
Install
pnpm add @multiplatform.one/storeWhat it owns
createStore(initialState, options?)— a TanStackStore, or aPersistStorewhenpersist: true(state survives reloads, keyed byname)useStore(store, selector?)— React hook with optional selectorcreatePersistStore, the platformstorageadapter, and raw TanStack re-exports (Store,batch,createTanStackStore,useTanStackStore)
What it must not do
- No server state — queries/mutations belong to TanStack Query (wired via
@multiplatform.one/core) or@multiplatform.one/frappelive collections - No UI
Usage
import { createStore, useStore } from "@multiplatform.one/store";
const appStore = createStore({ theme: "light" }, { name: "app", persist: true });
export function ThemeToggle() {
const theme = useStore(appStore, (s) => s.theme);
const toggle = () =>
appStore.setState((prev) => ({
...prev,
theme: prev.theme === "light" ? "dark" : "light",
}));
return <button onClick={toggle}>{theme}</button>;
}Persisted stores rehydrate from storage automatically on creation and expose
rehydrate() / clearPersistedState() for manual control.
License
Apache-2.0
