super-harness / src /hooks /use-update.ts
Cyber Catalyst Team
Deploy to HF Spaces with LFS
4782147
Raw
History Blame Contribute Delete
369 Bytes
import { isFunction, nextTick } from "lib/utils";
import { useCallback, useState } from "react";
export function useUpdate() {
const [, setState] = useState(0);
const update = useCallback((cb?: () => void) => {
nextTick().then(() => {
setState((prev) => prev + 1);
if (isFunction(cb)) {
cb();
}
});
}, []);
return update;
}