-
-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(usePrevious): revert the reworked variant as a fix of #1315
fix:#1315
- Loading branch information
Showing
1 changed file
with
6 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
import { useRef } from 'react'; | ||
import { useEffect, useRef } from 'react'; | ||
|
||
export default function usePrevious<T>(state: T): T | undefined { | ||
const curRef = useRef<T>(); | ||
const prevRef = useRef<T>(); | ||
const ref = useRef<T>(); | ||
|
||
prevRef.current = curRef.current; | ||
curRef.current = state; | ||
useEffect(() => { | ||
ref.current = state | ||
}); | ||
|
||
return prevRef.current; | ||
return ref.current; | ||
} |