Skip to content

🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.

366 B
Raw Blame
import { useEffect, useRef } from "react";

/** Returns the value saved after the previous committed render. */
export function usePrevious<T>(value: T, shouldSave = true): T | undefined {
  const previous = useRef<T | undefined>(undefined);

  useEffect(() => {
    if (shouldSave) previous.current = value;
  }, [value, shouldSave]);

  return previous.current;
}