Skip to content

Commit d2bb09d

Browse files
committed
Remove ref implementation useEffectOnce
1 parent 84973de commit d2bb09d

File tree

1 file changed

+2
-9
lines changed

1 file changed

+2
-9
lines changed

src/useEffectOnce.ts

+2-9
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,7 @@
1-
import {useRef, useEffect, EffectCallback} from 'react';
1+
import {useEffect, EffectCallback} from 'react';
22

33
const useEffectOnce = (effect: EffectCallback) => {
4-
const didRun = useRef(false);
5-
6-
useEffect(() => {
7-
if (!didRun.current) {
8-
didRun.current = true;
9-
return effect();
10-
}
11-
});
4+
useEffect(effect, []);
125
}
136

147
export default useEffectOnce;

0 commit comments

Comments
 (0)