diff --git a/src/usePrevious.ts b/src/usePrevious.ts index 658f0f68e6..69592b75ad 100644 --- a/src/usePrevious.ts +++ b/src/usePrevious.ts @@ -1,13 +1,11 @@ -import { useEffect, useRef } from 'react'; +import { useRef } from 'react'; -const usePrevious = (state: T): T | undefined => { - const ref = useRef(); +export default function usePrevious(state: T): T | undefined { + const curRef = useRef(); + const prevRef = useRef(); - useEffect(() => { - ref.current = state; - }); + prevRef.current = curRef.current; + curRef.current = state; - return ref.current; -}; - -export default usePrevious; + return prevRef.current; +}