valtio-reactive
Version:
valtio-reactive makes Valtio a reactive library
16 lines (13 loc) • 327 B
text/typescript
import { proxy } from 'valtio/vanilla';
import { watch } from './core.js';
export function computed<T extends object>(obj: {
[K in keyof T]: () => T[K];
}): T {
const computedState = proxy({}) as T;
for (const key in obj) {
watch(() => {
computedState[key] = obj[key]();
});
}
return computedState;
}