import { useEffect , useState } from 'react' ; param controlledBoolean param onSetBoolean const useOptionalControlledState = ( controlledBoolean ? , onSetBoolean ? ) => { const [ boolean , setBoolean ] = useState ( controlledBoolean || false ) ; useEffect ( ( ) => { if ( typeof controlledBoolean !== 'undefined' ) { setBoolean ( controlledBoolean ) ; } } , [ controlledBoolean , setBoolean ] ) ; useEffect ( ( ) => { if ( onSetBoolean ) { onSetBoolean ( boolean ) ; } } , [ boolean , onSetBoolean ] ) ; return [ boolean , setBoolean ] as const ; } ; export default useOptionalControlledState ;