You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: packages/docs/utils/storage/createLocalStorage.md
+4-4Lines changed: 4 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,14 +1,14 @@
1
-
# useLocalStorage
1
+
# createLocalStorage
2
2
3
-
Create a storage instance backed by `localStorage`. Values persist across page reloads and are synced across tabs via the `storage` event.
3
+
Create a storage instance backed by `globalThis.localStorage`. The underlying storage is resolved lazily from `globalThis` when the instance is used, so it can be imported before a browser-like global exists. Values persist across page reloads and are synced across tabs via the `storage` event when available.
Copy file name to clipboardExpand all lines: packages/docs/utils/storage/createSessionStorage.md
+4-4Lines changed: 4 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,14 +1,14 @@
1
-
# useSessionStorage
1
+
# createSessionStorage
2
2
3
-
Create a storage instance backed by `sessionStorage`. Values persist for the duration of the page session.
3
+
Create a storage instance backed by `globalThis.sessionStorage`. The underlying storage is resolved lazily from `globalThis` when the instance is used, so it can be imported before a browser-like global exists. Values persist for the duration of the page session when available.
A `StorageInstance<T>` with the following methods:
68
69
69
-
-**`get(key)`** — Get the value for a key. Returns `null` if not set.
70
+
-**`get(key)`** — Get the value for a key. Returns `undefined` if not set or if the stored value is corrupted.
70
71
-**`get(key, defaultValue)`** — Get the value for a key, returning `defaultValue` if not set.
71
-
-**`set(key, value)`** — Set a value. Pass `null` to remove the key.
72
+
-**`set(key, value)`** — Set a value. `null` is stored as a real value when your type allows it.
73
+
-**`delete(key)`** — Remove a key from storage. Subscribers are notified with `undefined`.
72
74
-**`has(key)`** — Check if a key exists in storage.
73
75
-**`keys()`** — List all keys managed by this instance. When a `prefix` is set, only prefixed keys are returned (with the prefix stripped).
74
-
-**`clear()`** — Remove all entries. When a `prefix` is set, only prefixed keys are cleared — other keys in the same provider are left untouched.
75
-
-**`subscribe(key, callback)`** — Subscribe to changes on a key. Returns an unsubscribe function. Listeners are notified on both local changes and external sync events (cross-tab, navigation).
76
+
-**`clear()`** — Remove all entries. When a `prefix` is set, only prefixed keys are cleared — other keys in the same provider are left untouched. Subscribers are notified with `undefined`.
77
+
-**`subscribe(key, callback)`** — Subscribe to changes on a key. Returns an unsubscribe function. Listeners are notified on both local changes and external sync events (cross-tab, navigation).`undefined` means the key is absent.
76
78
-**`destroy()`** — Clean up all listeners and event handlers.
79
+
80
+
::: warning Cleanup
81
+
Each `createStorage()` call registers a global event listener (when the provider has a `syncEvent`). Always call `destroy()` when the storage instance is no longer needed to avoid memory leaks — for example in a component's unmount/destroy lifecycle hook.
Copy file name to clipboardExpand all lines: packages/docs/utils/storage/createUrlSearchParamsInHashStorage.md
+9-3Lines changed: 9 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,16 +1,18 @@
1
-
# useUrlSearchParamsInHash
1
+
# createUrlSearchParamsInHashStorage
2
2
3
3
Create a storage instance backed by URL hash params (`#key=value`). Useful for client-side state that shouldn't be sent to the server, like tab selection or UI mode.
4
4
5
+
This storage is browser-only: it requires `window.location` and `window.history`. The browser context is checked when the provider is created. In non-browser environments, it falls back to a no-op provider.
6
+
5
7
By default, changes use `replaceState` to avoid polluting browser history. Use `{ push: true }` to create history entries instead.
All values are serialized with `JSON.stringify` before being written to the URL hash. This means string values will include quotes (e.g. `#tab=%22settings%22`). Use a custom `serializer` if you prefer raw strings.
0 commit comments