gilbarbara/react-dropdown

View on GitHub
src/modules/hooks.ts

Summary

Maintainability
A
0 mins
Test Coverage
A
100%
import { useEffect, useRef } from 'react';

export function usePrevious<T>(value: T): T {
  const ref: any = useRef<T>();

  useEffect(() => {
    ref.current = value;
  }, [value]);

  return ref.current;
}