Skip to content

Commit

Permalink
fix: useUpdateEffect run on the wrong time
Browse files Browse the repository at this point in the history
  • Loading branch information
brickspert authored Aug 12, 2019
1 parent 2ccde2f commit 1d5cd10
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions src/useUpdateEffect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@ import { useEffect, useRef } from 'react';
const useUpdateEffect: typeof useEffect = (effect, deps) => {
const isInitialMount = useRef(true);

useEffect(
isInitialMount.current
? () => {
isInitialMount.current = false;
}
: effect,
deps
);
useEffect(() => {
if (isInitialMount.current) {
isInitialMount.current = false;
} else {
effect();
}
}, deps);
};

export default useUpdateEffect;

0 comments on commit 1d5cd10

Please sign in to comment.