Comparing version 0.2.1 to 0.2.2
@@ -202,3 +202,3 @@ 'use strict'; | ||
exports.proxy = createProxy; | ||
exports.subscribeProxy = subscribe; | ||
exports.subscribe = subscribe; | ||
exports.useProxy = useProxy; |
declare const createProxy: <T extends object>(initialObject?: T) => T; | ||
declare const subscribe: (proxy: any, callback: () => void) => () => void; | ||
declare const useProxy: <T extends object>(proxy: T) => T; | ||
export { createProxy as proxy, useProxy, subscribe as subscribeProxy }; | ||
export { createProxy as proxy, useProxy, subscribe }; |
@@ -197,3 +197,3 @@ var valtio = (function (exports, react, proxyCompare, useSubscription) { | ||
exports.proxy = createProxy; | ||
exports.subscribeProxy = subscribe; | ||
exports.subscribe = subscribe; | ||
exports.useProxy = useProxy; | ||
@@ -200,0 +200,0 @@ |
@@ -183,2 +183,2 @@ import { useMemo, useRef, useEffect } from 'react'; | ||
export { createProxy as proxy, subscribe as subscribeProxy, useProxy }; | ||
export { createProxy as proxy, subscribe, useProxy }; |
{ | ||
"name": "valtio", | ||
"private": false, | ||
"version": "0.2.1", | ||
"version": "0.2.2", | ||
"description": "💊 Valtio makes proxy-state simple ", | ||
@@ -6,0 +6,0 @@ "main": "index.cjs.js", |
@@ -34,2 +34,4 @@ ![](/readme.svg) | ||
const snapshot = useProxy(state) | ||
// Rule of thumb: read from snapshots, mutate the source | ||
// The component renders when the snapshot-reads change | ||
return ( | ||
@@ -44,4 +46,17 @@ <div> | ||
### Subscribe from anywhere | ||
```js | ||
import { subscribe } from 'valtio' | ||
// Suscribe to all state changes | ||
const unsubscribe = subscribe(state, () => console.log(`state has changed to ${state}`)) | ||
// Unsubscribe by calling the result | ||
unsubscribe() | ||
// Subscribe to a portion of state | ||
subscribe(state.foo, () => console.log(`state.foo has changed to ${state.foo}`)) | ||
``` | ||
**And that's it!** | ||
</details> |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
19530
61