react-mnemonic 1.2.0-beta1 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,3 +1,8 @@
1
+ <p align="center">
2
+ <img src="./mne_logo-light.png#gh-light-mode-only" alt="react-mnemonic logo" width="220" />
3
+ <img src="./mne_logo.png#gh-dark-mode-only" alt="react-mnemonic logo" width="220" />
4
+ </p>
5
+
1
6
  # react-mnemonic
2
7
 
3
8
  AI-friendly, persistent, type-safe state for React.
@@ -62,8 +67,44 @@ survives a full page reload.
62
67
 
63
68
  - `react-mnemonic/core` for the lean persisted-state path
64
69
  - `react-mnemonic/schema` when you want schemas, validation, and migrations
70
+ - `react-mnemonic/optional` for component libraries that should persist when a provider exists and silently fall back to in-memory state otherwise
65
71
  - `react-mnemonic` if you need the backward-compatible root entrypoint
66
72
 
73
+ ## Optional persistence for component libraries
74
+
75
+ If your component may render inside or outside a `MnemonicProvider`, import the
76
+ optional hook instead of branching at the call site.
77
+
78
+ ```tsx
79
+ import { useMnemonicKeyOptional } from "react-mnemonic/optional";
80
+
81
+ function SearchBox() {
82
+ const { value, set, remove } = useMnemonicKeyOptional("draft", {
83
+ defaultValue: "",
84
+ });
85
+
86
+ return (
87
+ <div>
88
+ <input value={value} onChange={(event) => set(event.target.value)} />
89
+ <button onClick={remove}>Clear</button>
90
+ </div>
91
+ );
92
+ }
93
+ ```
94
+
95
+ Inside a provider, the draft is persisted. Outside a provider, the same hook
96
+ behaves like local in-memory state without throwing.
97
+
98
+ The lean optional entrypoint exports only:
99
+
100
+ - `useMnemonicKeyOptional(...)`
101
+ - `useMnemonicOptional()`
102
+ - `defineMnemonicKey(...)`
103
+
104
+ Schema metadata such as `schema: { version }` can still be passed through the
105
+ optional hook. Applications pay the schema/runtime cost only when they mount a
106
+ schema-capable `MnemonicProvider`.
107
+
67
108
  ## AI resources
68
109
 
69
110
  | Resource | Purpose |
@@ -79,6 +120,7 @@ survives a full page reload.
79
120
 
80
121
  - [Documentation home](https://thirtytwobits.github.io/react-mnemonic/)
81
122
  - [Quick Start](https://thirtytwobits.github.io/react-mnemonic/docs/getting-started/quick-start)
123
+ - [Optional Persistence](https://thirtytwobits.github.io/react-mnemonic/docs/guides/optional-persistence)
82
124
  - [Server Rendering](https://thirtytwobits.github.io/react-mnemonic/docs/guides/server-rendering)
83
125
  - [Canonical Key Definitions](https://thirtytwobits.github.io/react-mnemonic/docs/guides/canonical-key-definitions)
84
126
  - [Single Source of Truth Schemas](https://thirtytwobits.github.io/react-mnemonic/docs/guides/single-source-of-truth-schemas)