storion 0.10.0 → 0.10.1
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 +44 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -52,10 +52,41 @@ npm install storion
|
|
|
52
52
|
**Read state → Storion tracks it. State changes → Only affected components re-render.**
|
|
53
53
|
|
|
54
54
|
```tsx
|
|
55
|
-
import {
|
|
56
|
-
|
|
55
|
+
import { create } from "storion/react";
|
|
56
|
+
|
|
57
|
+
// Create store and hook in one call - no Provider needed!
|
|
58
|
+
const [counter, useCounter] = create({
|
|
59
|
+
state: { count: 0 },
|
|
60
|
+
setup({ state }) {
|
|
61
|
+
return {
|
|
62
|
+
inc: () => state.count++,
|
|
63
|
+
dec: () => state.count--,
|
|
64
|
+
};
|
|
65
|
+
},
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
function Counter() {
|
|
69
|
+
const { count, inc, dec } = useCounter((state, actions) => ({
|
|
70
|
+
count: state.count,
|
|
71
|
+
...actions,
|
|
72
|
+
}));
|
|
73
|
+
|
|
74
|
+
return (
|
|
75
|
+
<div>
|
|
76
|
+
<button onClick={dec}>-</button>
|
|
77
|
+
<span>{count}</span>
|
|
78
|
+
<button onClick={inc}>+</button>
|
|
79
|
+
</div>
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
<details>
|
|
85
|
+
<summary>Multi-store apps with StoreProvider</summary>
|
|
86
|
+
|
|
87
|
+
```tsx
|
|
88
|
+
import { store, useStore, StoreProvider } from "storion/react";
|
|
57
89
|
|
|
58
|
-
// Define a store
|
|
59
90
|
const counterStore = store({
|
|
60
91
|
name: "counter",
|
|
61
92
|
state: { count: 0 },
|
|
@@ -67,7 +98,6 @@ const counterStore = store({
|
|
|
67
98
|
},
|
|
68
99
|
});
|
|
69
100
|
|
|
70
|
-
// Use in React
|
|
71
101
|
function Counter() {
|
|
72
102
|
const { count, inc, dec } = useStore(({ get }) => {
|
|
73
103
|
const [state, actions] = get(counterStore);
|
|
@@ -82,8 +112,18 @@ function Counter() {
|
|
|
82
112
|
</div>
|
|
83
113
|
);
|
|
84
114
|
}
|
|
115
|
+
|
|
116
|
+
function App() {
|
|
117
|
+
return (
|
|
118
|
+
<StoreProvider>
|
|
119
|
+
<Counter />
|
|
120
|
+
</StoreProvider>
|
|
121
|
+
);
|
|
122
|
+
}
|
|
85
123
|
```
|
|
86
124
|
|
|
125
|
+
</details>
|
|
126
|
+
|
|
87
127
|
## Async State
|
|
88
128
|
|
|
89
129
|
```tsx
|