We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 8fb9d05 commit 8c6f467Copy full SHA for 8c6f467
src/usePrevious.ts
@@ -1,13 +1,11 @@
1
-import { useEffect, useRef } from 'react';
+import { useRef } from 'react';
2
3
-const usePrevious = <T>(state: T): T | undefined => {
4
- const ref = useRef<T>();
+export default function usePrevious<T>(state: T): T | undefined {
+ const curRef = useRef<T>();
5
+ const prevRef = useRef<T>();
6
- useEffect(() => {
7
- ref.current = state;
8
- });
+ prevRef.current = curRef.current;
+ curRef.current = state;
9
10
- return ref.current;
11
-};
12
-
13
-export default usePrevious;
+ return prevRef.current;
+}
0 commit comments