"use strict";

exports.__esModule = true;
exports.default = void 0;

var _react = require("react");

var useMergedState = function useMergedState(option) {
  var _ref = option || {},
      defaultValue = _ref.defaultValue,
      value = _ref.value;

  var _useState = (0, _react.useState)(function () {
    if (value !== undefined) {
      return value;
    }

    if (defaultValue !== undefined) {
      return typeof defaultValue === 'function' ? defaultValue() : defaultValue;
    }

    return undefined;
  }),
      innerValue = _useState[0],
      setInnerValue = _useState[1];

  var mergedValue = value !== undefined ? value : innerValue;

  function triggerChange(newValue) {
    setInnerValue(newValue);
  }

  return [mergedValue, triggerChange];
};

var _default = useMergedState;
exports.default = _default;