import '../../../../preact/compat/dist/compat.module.mjs';
import { useRef as _, useState as h, useCallback as T } from '../../../../preact/hooks/dist/hooks.module.mjs';

function useControlled({
  controlled,
  default: defaultProp,
  name,
  state = 'value'
}) {
  // isControlled is ignored in the hook dependency lists as it should never change.
  const {
    current: isControlled
  } = _(controlled !== undefined);
  const [valueState, setValue] = h(defaultProp);
  const value = isControlled ? controlled : valueState;
  const setValueIfUncontrolled = T(newValue => {
    if (!isControlled) {
      setValue(newValue);
    }
  }, []);
  return [value, setValueIfUncontrolled];
}

export { useControlled as default };
//# sourceMappingURL=useControlled.mjs.map
