2025-06-21 23:30:33 +03:00

18 lines
399 B
JavaScript

import { useLayoutEffect } from 'react';
import { useSnapshot } from 'valtio/react';
function useProxy(proxy, options) {
const snapshot = useSnapshot(proxy, options);
let isRendering = true;
useLayoutEffect(() => {
isRendering = false;
});
return new Proxy(proxy, {
get(target, prop) {
return isRendering ? snapshot[prop] : target[prop];
}
});
}
export { useProxy };