'use strict';

var React = require('react');

function useMemoCompare(next, compare) {
  const previousRef = React.useRef();
  const previous = previousRef.current;
  const isEqual = compare(previous, next);
  React.useEffect(() => {
    if (!isEqual) {
      previousRef.current = next;
    }
  });
  return isEqual ? previous : next;
}

module.exports = useMemoCompare;
