"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.useRefCallbackHandler = useRefCallbackHandler;
exports.default = void 0;

var _react = require("react");

// a variant of https://medium.com/@teh_builder/ref-objects-inside-useeffect-hooks-eb7c15198780
function useRefCallbackHandler(handler) {
  const ref = (0, _react.useRef)(null);
  const setRef = (0, _react.useCallback)(node => {
    if (ref.current) {// Make sure to cleanup any events/references added to the last instance
    }

    if (node && handler) {
      handler(node);
    } // Save a reference to the node


    ref.current = node;
  }, [handler]);
  return [setRef];
}

var _default = useRefCallbackHandler;
exports.default = _default;