Skip to content

Commit

Permalink
Remove ref implementation useEffectOnce
Browse files Browse the repository at this point in the history
  • Loading branch information
wardoost committed Mar 31, 2019
1 parent 84973de commit d2bb09d
Showing 1 changed file with 2 additions and 9 deletions.
11 changes: 2 additions & 9 deletions src/useEffectOnce.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
import {useRef, useEffect, EffectCallback} from 'react';
import {useEffect, EffectCallback} from 'react';

const useEffectOnce = (effect: EffectCallback) => {
const didRun = useRef(false);

useEffect(() => {
if (!didRun.current) {
didRun.current = true;
return effect();
}
});
useEffect(effect, []);
}

export default useEffectOnce;

0 comments on commit d2bb09d

Please sign in to comment.