import { useEffect, useRef } from "react";

export default function usePrevious(current) {
  const ref = useRef(current);

  // will be updated on the next render
  useEffect(() => {
    ref.current = current;
  });

  // return the existing current (pre render)
  return ref;
}
