{"repo":"pmndrs/valtio","free":true,"listed":false,"github":"https://github.com/pmndrs/valtio","clone":"git clone https://github.com/pmndrs/valtio.git","description":"🧙 Valtio makes proxy-state simple for React and Vanilla","language":"TypeScript","stars":10223,"topics":["react","state","mutable","proxy"],"license":"MIT","category":"networking-infra","readme_excerpt":"npm install valtio makes proxy-state simple Wrap your state object Valtio turns the object you pass it into a self-aware proxy. Mutate from anywhere You can make changes to it in the same way you would to a normal js-object. React via useSnapshot Create a local snapshot that catches changes. Rule of thumb: read from snapshots in render function, otherwise use the source. The component will only re-render when the parts of the state you access have changed, it is render-optimized. Note for TypeScript users: Return type of useSnapshot can be too strict. The snap variable returned by useSnapshot is a (deeply) read-only object. Its type has readonly attribute, which may be too strict for some use cases. To mitigate typing difficulties, you might want to loosen the type definition: See #327 for more information. Note: useSnapshot returns a new proxy for render optimization. Internally, useSnapshot calls snapshot in valtio/vanilla, and wraps the snapshot object with another proxy to detect property access. This feature is based on proxy-compare. Two kinds of proxies are used for different purposes: - proxy() from valtio/vanilla is for mutation tracking or write tracking. - createProxy() from proxy-compare is for usage tracking or read tracking. Use of this is for expert users. Valtio tries best to handle this behavior but it's hard to understand without familiarity. To avoid this pitfall, the recommended pattern is not to use this and prefer arrow function. If you are new to this, ","default_branch":null,"files":null,"tree":[],"storefront":"/r/pmndrs","claimed":false,"request_supported":{"post":"https://gitbuyer.com/r/pmndrs/valtio/request-supported","requests":0},"note":"indexed from public GitHub; nothing is for sale on this page. Clone it from GitHub. Paid listings live at /search."}