"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = usePrevious;
var _react = require("react");
/**
 * A convenience hook that will return the value of the input
 * from the previous render. You could consider this the class
 * component equivalent of `prevProps` from the life cycle
 * method: `componentDidUpdate`.
 *
 * Example:
 *
 * function myComponent(isVisible) {
 *  const [state, setState] = useState(initialState);
 *  const wasPreviouslyVisible = usePrevious(isVisible);
 *
 *  useEffect(() => {
 *    if (isVisible && !wasPreviouslyVisible) {
 *      setState(initialState);
 *    }
 *  }, [isVisible]);
 * }
 */

function usePrevious(value, initialValue = null) {
  const ref = (0, _react.useRef)(initialValue);
  (0, _react.useEffect)(() => {
    ref.current = value;
  });
  return ref.current;
}