1 | import { useEffect, useLayoutEffect, useRef } from 'react';
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 | export default function useIsInitialRenderRef() {
|
10 | const effectCount = useRef(0);
|
11 | const isInitialRenderRef = useRef(true);
|
12 | useLayoutEffect(() => {
|
13 | effectCount.current += 1;
|
14 | if (effectCount.current >= 2) {
|
15 | isInitialRenderRef.current = false;
|
16 | }
|
17 | });
|
18 |
|
19 |
|
20 | useEffect(() => () => {
|
21 | effectCount.current = 0;
|
22 | isInitialRenderRef.current = true;
|
23 | }, []);
|
24 | return isInitialRenderRef;
|
25 | } |
\ | No newline at end of file |