teamdigitale/italia-app

View on GitHub
ts/utils/hooks/usePrevious.ts

Summary

Maintainability
A
0 mins
Test Coverage
import { useEffect, useRef } from "react";

/**
 * Hook used to store the _previous_ value
 * in a React functional component.
 */
export function usePrevious<T>(value: T) {
  const ref = useRef<T>();

  useEffect(() => {
    // eslint-disable-next-line
    ref.current = value;
  }, [value]);

  return ref.current;
}