"use strict";
'use client';

var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.useValueChanged = useValueChanged;
var React = _interopRequireWildcard(require("react"));
var _useIsoLayoutEffect = require("@base-ui/utils/useIsoLayoutEffect");
var _useStableCallback = require("@base-ui/utils/useStableCallback");
function useValueChanged(value, onChange) {
  const valueRef = React.useRef(value);
  const onChangeCallback = (0, _useStableCallback.useStableCallback)(onChange);
  (0, _useIsoLayoutEffect.useIsoLayoutEffect)(() => {
    if (valueRef.current === value) {
      return;
    }
    onChangeCallback(valueRef.current);
  }, [value, onChangeCallback]);
  (0, _useIsoLayoutEffect.useIsoLayoutEffect)(() => {
    valueRef.current = value;
  }, [value]);
}