import { useState } from 'react';

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

  var _useState = 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];
};

export default useMergedState;