Skip to content

Commit

Permalink
fix(usePrevious): revert the reworked variant as a fix of #1315
Browse files Browse the repository at this point in the history
fix:#1315
  • Loading branch information
xobotyi committed Jun 29, 2020
1 parent c768c06 commit a4279eb
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/usePrevious.ts
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;
}

0 comments on commit a4279eb

Please sign in to comment.