import { useCallback, useEffect, useState, useRef } from "react";
var noop = function noop() {};
var emptyObj = {};
export default (function (defaultRowSelection, onChange) {
  if (defaultRowSelection === void 0) {
    defaultRowSelection = emptyObj;
  }
  if (onChange === void 0) {
    onChange = noop;
  }
  var _useState = useState(function () {
      return defaultRowSelection;
    }),
    rowSelection = _useState[0],
    setRowSelection = _useState[1];
  var initialSetRef = useRef(false);
  useEffect(function () {
    if (rowSelection === defaultRowSelection) return;

    // initialSetRef.current = true
    setRowSelection(defaultRowSelection);
  }, [defaultRowSelection]);
  var onRowSelectionChange = useCallback(function (getValue) {
    onChange(getValue(rowSelection));
    setRowSelection(getValue(rowSelection));
  }, [rowSelection]);
  return [rowSelection, onRowSelectionChange];
});