@t8/react-store 1.0.28 → 1.0.30
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 +21 -5
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -4,10 +4,26 @@
|
|
|
4
4
|
|
|
5
5
|
*Concise shared state management for React apps*
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
🔹 Similar to `useState()`
|
|
8
|
+
|
|
9
|
+
```diff
|
|
10
|
+
+ let store = new Store(0);
|
|
11
|
+
|
|
12
|
+
let Counter = () => {
|
|
13
|
+
- let [counter, setCounter] = useState(0);
|
|
14
|
+
+ let [counter, setCounter] = useStore(store);
|
|
15
|
+
|
|
16
|
+
let handleClick = () => {
|
|
17
|
+
setCounter(value => value + 1);
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
return <button onClick={handleClick}>+ {counter}</button>;
|
|
21
|
+
};
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
🔹 No boilerplate<br>
|
|
25
|
+
🔹 Painless transition from local state<br>
|
|
26
|
+
🔹 SSR- and CSR-compatible
|
|
11
27
|
|
|
12
28
|
Installation: `npm i @t8/react-store`
|
|
13
29
|
|
|
@@ -140,7 +156,7 @@ let ItemCard = ({ id }) => {
|
|
|
140
156
|
|
|
141
157
|
## Store data
|
|
142
158
|
|
|
143
|
-
A store can contain data of any type.
|
|
159
|
+
A store can contain data of any type. With TypeScript, the type of a store containing data of type `T` is `Store<T>` which can be inferred from the data passed to `new Store(data)`.
|
|
144
160
|
|
|
145
161
|
Live demos:<br>
|
|
146
162
|
[Primitive value state](https://codesandbox.io/p/sandbox/rtng37?file=%2Fsrc%2FPlusButton.jsx)<br>
|