UNPKG

@hitachivantara/uikit-react-core

Version:

Core React components for the NEXT Design System.

19 lines (18 loc) 627 B
"use strict"; Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" }); const React = require("react"); const useControlled = (controlledProp, initialState) => { const { current: isControlled } = React.useRef(controlledProp !== void 0); const [valueState, setValue] = React.useState(initialState); const value = isControlled ? controlledProp : valueState; const setValueIfUncontrolled = React.useCallback( (newValue) => { if (!isControlled) { setValue(newValue); } }, [isControlled] ); return [value, setValueIfUncontrolled]; }; exports.useControlled = useControlled;