UNPKG

@hitachivantara/uikit-react-core

Version:
16 lines (15 loc) 408 B
import { useRef, useState } from "react"; //#region src/hooks/useComputation.ts var useComputation = (valueFn, valueFallback) => { const computed = useRef(null); const [value, setValue] = useState(valueFallback); const computeValue = () => { if (!computed.current) { setValue(valueFn?.()); computed.current = true; } }; return [value, computeValue]; }; //#endregion export { useComputation };