Persist values in native storage
Persist a theme preference with local or session lifetime.
The example stores `dark`, reads it for rendering, removes the saved key and cleans up the named store.
Table of contents
Main APIs
- StorageType
- Identifies the native storage strategies accepted by createNativeStore.
- createNativeStore
- Creates a named store with the selected storage type, or returns it when reuse is enabled.
- NativeStorageInterface
- Type. Public surface returned by createNativeStore.
tsimport { mount } from "valyrian.js";
import { StorageType, createNativeStore } from "valyrian.js/native-store";
const preferences = createNativeStore("preferences", {}, StorageType.Local);
preferences.set("theme", "dark");
const savedTheme = preferences.get("theme");
preferences.delete("theme");
mount("body", () => `Saved theme: ${savedTheme}`);
preferences.cleanup();