@hitachivantara/uikit-react-core
Version:
UI Kit Core React components.
12 lines (11 loc) • 460 B
JavaScript
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 };