"use strict";

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