You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
|`useStore`|`Proxy`| Proxy hook to consume and update store properties inside your components. Each time the value changes, the component is rendered again with the new value. More [info](#usestore-hook). |`const [price, setPrice] = useStore.cart.price()`|
113
114
|`getStore`|`Proxy`| Similar to `useStore` but without subscription. You can use it as a helper outside (or inside) components. Note that if the value changes, it does not cause a rerender. More [info](#getstore-helper). |`const [price, setPrice] = getStore.cart.price()`|
115
+
|`setStore`|`Proxy`| It's a proxy helper to modify a store property outside (or inside) components. More [info](#setstore-helper). |`setStore.user.name('Aral')` or `setStore.cart.price(price => price + 10)`|
114
116
|`withStore`|`Proxy`| HoC with `useStore` inside. Useful for components that are not functional. More [info](#withstore-hoc). |`withStore.cart.price(MyComponent)`|
115
117
116
118
### How to export
@@ -231,6 +233,75 @@ Is an `Array` with **2** items:
231
233
| update value |`function`| Function to update the store property indicated with the proxy. | Updating a store portion:<div>`const [count, setCount] = useStore.count(0)`</div>Way 1:<div>`setCount(count + 1)`</div>Way 1:<div>`setCount(c => c + 1)`</div><div>-------</div>Updating all store:<div>`const [store, updateStore] = useStore()`</div>Way 1:<div>`updateStore({ ...store, count: 2 }))`</div>Way 1:<div>`updateStore(s => ({ ...s, count: 2 }))`</div> |
232
234
233
235
236
+
### setStore helper
237
+
238
+
Useful helper to modify the store from anywhere (outside/inside components).
This causes a re-render on all components that are consuming any of the form properties, instead of just the one that has been updated. So using the `setStore` proxy helper is more recommended.
304
+
234
305
### getStore helper
235
306
236
307
It works exactly like `useStore` but with **some differences**:
If you have to update several properties and you don't want to disturb the rest of the components that are using other store properties you can create a helper with `getStore`.
0 commit comments