import { useCallback, useEffect, useState, useRef } from "react";
var noop = function noop() {};
var emptyObj = {};
export default (function (defaultPinning, onChange) {
  if (defaultPinning === void 0) {
    defaultPinning = emptyObj;
  }
  if (onChange === void 0) {
    onChange = noop;
  }
  var _useState = useState(function () {
      return defaultPinning;
    }),
    pinning = _useState[0],
    setPinning = _useState[1];
  var initialSetRef = useRef(false);
  useEffect(function () {
    if (!defaultPinning || pinning === defaultPinning) return;
    initialSetRef.current = true;
    setPinning(defaultPinning);
  }, [defaultPinning]);
  var onPin = useCallback(function (value) {
    onChange(value);
    setPinning(value);
  }, []);
  return [pinning, onPin];
});