state-jet 2.0.11 → 2.0.12
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 +20 -9
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -41,7 +41,9 @@ Or if you're using `cdn`:
|
|
|
41
41
|
<script src="https://cdn.jsdelivr.net/npm/state-jet@latest/dist/index.cjs"></script>
|
|
42
42
|
```
|
|
43
43
|
|
|
44
|
-
##
|
|
44
|
+
## GlobalState
|
|
45
|
+
|
|
46
|
+
The `useStateGlobal` hook is the simplest entry point to State-Jet. It allows you to create stateful values that can be accessed and updated from any component in your application, regardless of their location in the component tree.
|
|
45
47
|
|
|
46
48
|
### Create GlobalState
|
|
47
49
|
|
|
@@ -56,7 +58,7 @@ function Counter() {
|
|
|
56
58
|
}
|
|
57
59
|
```
|
|
58
60
|
|
|
59
|
-
##
|
|
61
|
+
## Slices
|
|
60
62
|
|
|
61
63
|
Slices in state-jet represent logical groupings of state that help organize application data into manageable pieces. Unlike the global state approach which uses a single namespace, slices allow for partitioning state into named segments, making state management more modular and maintainable.
|
|
62
64
|
|
|
@@ -74,9 +76,9 @@ export const useProductSlice = () => productSlice("list", []);
|
|
|
74
76
|
export const useCartSlice = () => cartSlice("list", []);
|
|
75
77
|
```
|
|
76
78
|
|
|
77
|
-
##
|
|
79
|
+
## Store
|
|
78
80
|
|
|
79
|
-
The useStore hook serves as a mechanism to group related slices of state into a cohesive store, enabling modular and organized state management in React applications. It creates a persistent reference to a collection of slice instances that can be accessed throughout an application component tree.
|
|
81
|
+
The `useStore` hook serves as a mechanism to group related slices of state into a cohesive store, enabling modular and organized state management in React applications. It creates a persistent reference to a collection of slice instances that can be accessed throughout an application component tree.
|
|
80
82
|
|
|
81
83
|
### Create Store
|
|
82
84
|
|
|
@@ -94,6 +96,8 @@ export const store = () => useStore(initializer);
|
|
|
94
96
|
|
|
95
97
|
## Middlewares
|
|
96
98
|
|
|
99
|
+
Middleware in state-jet is a powerful mechanism for intercepting, transforming, and processing state updates before they are applied to the store.
|
|
100
|
+
|
|
97
101
|
Unlike other libraries, you do not need to rely on any external dependencies. A `middleware` property from `options` helps to add middleware for state-jet.
|
|
98
102
|
|
|
99
103
|
```bash
|
|
@@ -252,16 +256,23 @@ const todoState = useStateGlobal<Todo[]>("todos", []);
|
|
|
252
256
|
|
|
253
257
|
## Why state-jet Is More Advanced Than Zustand
|
|
254
258
|
|
|
255
|
-
- **No Proxies Needed**
|
|
256
|
-
|
|
257
|
-
- **
|
|
258
|
-
|
|
259
|
-
- **
|
|
259
|
+
- **No Proxies Needed**
|
|
260
|
+
→ Zustand uses proxies for state updates, but state-jet uses signals, making it even faster.
|
|
261
|
+
- **Derived State Is Automatic**
|
|
262
|
+
→ No need for selectors; state updates only trigger where necessary.
|
|
263
|
+
- **Optimistic Updates & Rollback**
|
|
264
|
+
→ Unlike Zustand, state-jet has built-in support for instant UI updates and auto-revert on failures.
|
|
265
|
+
- **Multi-Tab Sync**
|
|
266
|
+
→ global state persists across browser tabs and devices.
|
|
267
|
+
- **CRDT Support**
|
|
268
|
+
→ Automatic conflict resolution for real-time apps, something even Zustand lacks.
|
|
269
|
+
|
|
260
270
|
|
|
261
271
|
### ✅ Conclusion
|
|
262
272
|
|
|
263
273
|
If you need the simplest, fastest, and most advanced state management solution for React, state-jet beats Redux, Recoil, MobX, Jotai, and even Zustand in performance, reactivity, and developer experience. 🚀
|
|
264
274
|
|
|
275
|
+
|
|
265
276
|
## ⚡ Comparison Table
|
|
266
277
|
| Feature | Redux | Recoil | MobX | Jotai | Zustand | state-jet |
|
|
267
278
|
|--------------------------|--------|--------|-------|--------|------------------------|----------------------|
|