react-mnemonic 1.2.1-beta1.0 → 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 +42 -0
- package/dist/core.cjs +1645 -1027
- package/dist/core.cjs.map +1 -1
- package/dist/core.d.cts +3 -2
- package/dist/core.d.ts +3 -2
- package/dist/core.js +1646 -1028
- package/dist/core.js.map +1 -1
- package/dist/index.cjs +1635 -1383
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +1636 -1384
- package/dist/index.js.map +1 -1
- package/dist/key-Bad1hAKN.d.cts +47 -0
- package/dist/key-QIDPiubI.d.ts +47 -0
- package/dist/optional.cjs +166 -0
- package/dist/optional.cjs.map +1 -0
- package/dist/optional.d.cts +13 -0
- package/dist/optional.d.ts +13 -0
- package/dist/optional.js +162 -0
- package/dist/optional.js.map +1 -0
- package/dist/schema.cjs +1635 -1383
- package/dist/schema.cjs.map +1 -1
- package/dist/schema.d.cts +3 -2
- package/dist/schema.d.ts +3 -2
- package/dist/schema.js +1636 -1384
- package/dist/schema.js.map +1 -1
- package/dist/{key-BvFvcKiR.d.cts → types-DcdXbmVl.d.cts} +88 -45
- package/dist/{key-BvFvcKiR.d.ts → types-DcdXbmVl.d.ts} +88 -45
- package/package.json +11 -1
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)
|