useLatest.tsx 307 Bytes
Newer Older
Yoon, Daeki's avatar
Yoon, Daeki committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
/**
 * 출처: https://github.com/jaredLunde/react-hook
 */
import { useRef, useEffect } from "react";

const useLatest = <T extends any>(current: T) => {
  const storedValue = useRef(current);
  useEffect(() => {
    storedValue.current = current;
  });
  return storedValue;
};

export default useLatest;