UNPKG

@hitachivantara/uikit-react-core

Version:
12 lines (11 loc) 460 B
import { useCallback, useRef, useState } from "react"; //#region src/hooks/useControlled.ts var useControlled = (controlledProp, initialState) => { const { current: isControlled } = useRef(controlledProp !== void 0); const [valueState, setValue] = useState(initialState); return [isControlled ? controlledProp : valueState, useCallback((newValue) => { if (!isControlled) setValue(newValue); }, [isControlled])]; }; //#endregion export { useControlled };