state-jet 2.0.8 → 2.0.9
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 +7 -10
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -70,26 +70,23 @@ import { useSlice } from "state-jet";
|
|
|
70
70
|
|
|
71
71
|
const productSlice = useSlice("products");
|
|
72
72
|
const cartSlice = useSlice("cart");
|
|
73
|
-
const userSlice = useSlice("user");
|
|
74
73
|
|
|
75
74
|
export const useProductSlice = () => productSlice("list", []);
|
|
76
|
-
export const useCartSlice = () => cartSlice("
|
|
77
|
-
export const useUserSlice = () => userSlice("info", null);
|
|
75
|
+
export const useCartSlice = () => cartSlice("list", []);
|
|
78
76
|
```
|
|
79
77
|
|
|
80
78
|
## Create Store
|
|
81
79
|
|
|
82
80
|
```tsx
|
|
83
81
|
import { useStore } from "state-jet";
|
|
84
|
-
import { useProductSlice, useCartSlice
|
|
82
|
+
import { useProductSlice, useCartSlice } from "./slices";
|
|
85
83
|
|
|
86
84
|
const initializer: any = () => ({
|
|
87
85
|
products: useProductSlice(),
|
|
88
86
|
cart: useCartSlice(),
|
|
89
|
-
user: useUserSlice()
|
|
90
87
|
});
|
|
91
88
|
|
|
92
|
-
export const
|
|
89
|
+
export const store = () => useStore(initializer);
|
|
93
90
|
```
|
|
94
91
|
|
|
95
92
|
## Middlewares
|
|
@@ -98,8 +95,8 @@ Unlike other libraries, you do not need to rely on any external dependencies. A
|
|
|
98
95
|
|
|
99
96
|
```bash
|
|
100
97
|
function useStateGlobal<T>(
|
|
101
|
-
|
|
102
|
-
|
|
98
|
+
...
|
|
99
|
+
options?: { middleware?: [] }
|
|
103
100
|
)
|
|
104
101
|
```
|
|
105
102
|
|
|
@@ -197,7 +194,7 @@ const optimisticMiddleware = (apiUrl: string) => {
|
|
|
197
194
|
};
|
|
198
195
|
};
|
|
199
196
|
const profile = useStateGlobal("profile", { name: "John" }, {
|
|
200
|
-
|
|
197
|
+
middleware: [optimisticMiddleware("/update-profile")],
|
|
201
198
|
});
|
|
202
199
|
```
|
|
203
200
|
|
|
@@ -225,7 +222,7 @@ export default function Profile() {
|
|
|
225
222
|
<h1>Age: {age}</h1>
|
|
226
223
|
<button
|
|
227
224
|
onClick={() => {
|
|
228
|
-
counter.set(-5) //Age will be 0 eventhough it updated with negative value due to middleware logic
|
|
225
|
+
counter.set(-5) // Age will be 0 eventhough it updated with negative value due to middleware logic
|
|
229
226
|
}}>
|
|
230
227
|
Set negative
|
|
231
228
|
</button>
|