UNPKG

react-rv

Version:

react-rv is a lightweight and efficient state management library for React that allows you to create reactive variables and subscribe to them with minimal overhead.

2 lines 640 B
var R=(e,t)=>e===t;function u(e,t){let{eq:r=R,on:s}=t??{},o=new Set;s&&o.add(s);let f=(...n)=>{if(n.length===0)return e;let[p,i]=n,T=r;if(typeof i?.eq<"u"&&(T=i.eq===!1?R:i.eq),T(e,p))return e;let c=e;return e=p,o.forEach(v=>v(p,c)),e};return f.off=n=>void o.delete(n),f.size=()=>o.size,f.on=n=>(o.add(n),()=>{o.delete(n)}),f}u.fn=(e,t)=>u(e(),t);import{useSyncExternalStore as m}from"use-sync-external-store/shim";var d=e=>m(e.on,e,e);import{useEffect as x,useRef as y}from"react";function a(e,t){let r=y(t);r.current=t,x(()=>e.on((...s)=>r.current(...s)),[e])}export{u as rv,d as useRv,a as useRvEffect}; //# sourceMappingURL=index.js.map