preact-arco-design
Version:
Arco Design React UI Library.
39 lines (35 loc) • 815 B
JavaScript
var __read = this && this.__read || function (o, n) {
var m = typeof Symbol === "function" && o[Symbol.iterator];
if (!m) return o;
var i = m.call(o),
r,
ar = [],
e;
try {
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) {
ar.push(r.value);
}
} catch (error) {
e = {
error: error
};
} finally {
try {
if (r && !r.done && (m = i["return"])) m.call(i);
} finally {
if (e) throw e.error;
}
}
return ar;
};
import { useState, useEffect } from "preact/compat";
export default function useComputedState(computed, deps) {
var _a = __read(useState(computed()), 2),
state = _a[0],
setState = _a[1];
useEffect(function () {
var newState = computed();
setState(newState);
}, [deps]);
return state;
}