import { useCallback, useEffect, useRef, useState } from "react";
var noop = function noop() {};
export default (function (defaultGrouping, onChange) {
  if (defaultGrouping === void 0) {
    defaultGrouping = "";
  }
  if (onChange === void 0) {
    onChange = noop;
  }
  var _useState = useState(defaultGrouping),
    grouping = _useState[0],
    setGrouping = _useState[1];
  var initialSetRef = useRef(false);
  useEffect(function () {
    if (grouping === defaultGrouping) return;
    initialSetRef.current = true;
    setGrouping(defaultGrouping);
  }, [defaultGrouping]);
  var onGroupingChange = useCallback(function (value) {
    onChange(value);
    setGrouping(value);
  }, [onChange]);
  return [grouping, onGroupingChange];
});