// src/hooks/useOverwritableState.ts
import { useEffect, useState } from "react";

// src/utils/resolveSetState.ts
function resolveSetState(action, prev) {
  return typeof action === "function" ? action(prev) : action;
}

// src/hooks/useOverwritableState.ts
var useOverwritableState = (initialValue, onChange) => {
  const [state, setState] = useState(initialValue);
  useEffect(() => {
    setState(initialValue);
  }, [initialValue]);
  const onChangeWrapper = (action) => {
    const resolved = resolveSetState(action, state);
    setState(resolved);
    onChange?.(state);
  };
  return [state, onChangeWrapper];
};
export {
  useOverwritableState
};
//# sourceMappingURL=useOverwritableState.js.map