@blabbing/signals
Version:
A reactive state management tool
21 lines (20 loc) • 507 B
JavaScript
import { useMemo as a, useSyncExternalStore as o } from "react";
import { Signal as h } from "@blabbing/signals";
let t = [];
function i() {
t.forEach((e) => e()), t = [];
}
const f = (e) => {
const [s, c] = a(() => [(r) => {
const u = () => {
n.watch(), r();
}, n = new h.subtle.Watcher(() => {
t.length === 0 && queueMicrotask(i), t.push(u);
});
return n.watch(e._c), () => n.unwatch(e._c);
}, () => e._c.get()], [e]);
return o(s, c, c);
};
export {
f as useValue
};