one
Version:
One is a new React Framework that makes Vite serve both native and web.
27 lines (26 loc) • 751 B
JavaScript
import { useLayoutEffect, useState } from "react";
function useQuery(q, enable = true) {
const queryImpl = q;
const [snapshot, setSnapshot] = useState(void 0);
const [, setView] = useState(void 0);
useLayoutEffect(() => {
if (enable) {
const view = q.materialize();
setView(view);
const unsubscribe = view.addListener(snapshot2 => {
setSnapshot(structuredClone(snapshot2));
});
view.hydrate();
return () => {
unsubscribe();
view.destroy();
};
}
setSnapshot(queryImpl.singular ? void 0 : []);
setView(void 0);
return () => {};
}, [JSON.stringify(enable ? q.ast : null)]);
return snapshot;
}
export { useQuery };
//# sourceMappingURL=useQueryZero.mjs.map