react-mnemonic 1.2.1-beta1.0 → 1.4.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.
@@ -60,9 +65,52 @@ survives a full page reload.
60
65
 
61
66
  ## Pick the right entrypoint
62
67
 
63
- - `react-mnemonic/core` for the lean persisted-state path
64
- - `react-mnemonic/schema` when you want schemas, validation, and migrations
65
- - `react-mnemonic` if you need the backward-compatible root entrypoint
68
+ | Entrypoint | Approx ESM size | Use when |
69
+ | -------------------------- | --------------- | ----------------------------------------------------------------------------------- |
70
+ | `react-mnemonic/optional` | ~4.9 KB | You want the tiny component-library shim that falls back to local memory |
71
+ | `react-mnemonic/bootstrap` | ~25 KB | You need synchronous first-paint recall before React renders |
72
+ | `react-mnemonic/core` | ~61 KB | A provider is required and you want the lean persisted-state path |
73
+ | `react-mnemonic/schema` | ~80.5 KB | A provider is required and you want schema validation, autoschema, and migrations |
74
+ | `react-mnemonic` | ~80.5 KB | You want the top-level full entrypoint with the same schema-capable runtime surface |
75
+
76
+ These are rough current estimates from the built ESM entry files in `dist/`
77
+ before consumer-side minification and tree-shaking. They are useful for
78
+ relative comparison, not as a hard size guarantee.
79
+
80
+ ## Optional persistence for component libraries
81
+
82
+ If your component may render inside or outside a `MnemonicProvider`, import the
83
+ optional hook instead of branching at the call site.
84
+
85
+ ```tsx
86
+ import { useMnemonicKeyOptional } from "react-mnemonic/optional";
87
+
88
+ function SearchBox() {
89
+ const { value, set, remove } = useMnemonicKeyOptional("draft", {
90
+ defaultValue: "",
91
+ });
92
+
93
+ return (
94
+ <div>
95
+ <input value={value} onChange={(event) => set(event.target.value)} />
96
+ <button onClick={remove}>Clear</button>
97
+ </div>
98
+ );
99
+ }
100
+ ```
101
+
102
+ Inside a provider, the draft is persisted. Outside a provider, the same hook
103
+ behaves like local in-memory state without throwing.
104
+
105
+ The lean optional entrypoint exports only:
106
+
107
+ - `useMnemonicKeyOptional(...)`
108
+ - `useMnemonicOptional()`
109
+ - `defineMnemonicKey(...)`
110
+
111
+ Schema metadata such as `schema: { version }` can still be passed through the
112
+ optional hook. Applications pay the schema/runtime cost only when they mount a
113
+ schema-capable `MnemonicProvider`.
66
114
 
67
115
  ## AI resources
68
116
 
@@ -79,6 +127,7 @@ survives a full page reload.
79
127
 
80
128
  - [Documentation home](https://thirtytwobits.github.io/react-mnemonic/)
81
129
  - [Quick Start](https://thirtytwobits.github.io/react-mnemonic/docs/getting-started/quick-start)
130
+ - [Optional Persistence](https://thirtytwobits.github.io/react-mnemonic/docs/guides/optional-persistence)
82
131
  - [Server Rendering](https://thirtytwobits.github.io/react-mnemonic/docs/guides/server-rendering)
83
132
  - [Canonical Key Definitions](https://thirtytwobits.github.io/react-mnemonic/docs/guides/canonical-key-definitions)
84
133
  - [Single Source of Truth Schemas](https://thirtytwobits.github.io/react-mnemonic/docs/guides/single-source-of-truth-schemas)