Skip to content

Commit

Permalink
fix: mutate ref in render directly
Browse files Browse the repository at this point in the history
  • Loading branch information
ClementParis016 committed May 13, 2020
1 parent d6fe267 commit 5488f5e
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions src/useLatest.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import { useRef, useEffect, MutableRefObject } from 'react';
import { useRef, MutableRefObject } from 'react';

const useLatest = <T>(value: T): MutableRefObject<T> => {
const latest = useRef<T>(value);

useEffect(() => {
latest.current = value;
}, [value]);
latest.current = value;

return latest;
};
Expand Down

0 comments on commit 5488f5e

Please sign in to comment.