import { useRef , useState , useCallback } from 'react' ; param controlledValue param defaultValue param formatValue function useControlled < T = any > ( controlledValue , defaultValue ? ) { const controlledRef = useRef ( false ) ; controlledRef . current = controlledValue !== undefined ; const [ uncontrolledValue , setUncontrolledValue ] = useState ( defaultValue ) ; const value = controlledRef . current ? controlledValue : uncontrolledValue ; const setValue = useCallback ( nextValue => { if ( ! controlledRef . current ) { setUncontrolledValue ( nextValue ) ; } } , [ controlledRef ] ) ; return [ value , setValue , controlledRef . current ] ; } export default useControlled ;