import { useCallback, useEffect, useState, useRef } from "react";
var noop = function noop() {};
var emptyArr = [];
export default (function (defaultSorting, onChange) {
  if (defaultSorting === void 0) {
    defaultSorting = emptyArr;
  }
  if (onChange === void 0) {
    onChange = noop;
  }
  var _useState = useState(function () {
      return defaultSorting;
    }),
    sorting = _useState[0],
    setSorting = _useState[1];
  var initialSetRef = useRef(false);
  useEffect(function () {
    if (sorting === defaultSorting) return;
    initialSetRef.current = true;
    setSorting(defaultSorting);
  }, [defaultSorting]);
  var onSortingChange = useCallback(function (getValue) {
    onChange(getValue(sorting));
    setSorting(getValue(sorting));
  }, [sorting]);
  return [sorting, onSortingChange];
});