1 | import { useLayoutEffect, useRef } from 'react';
|
2 | /**
|
3 | * A custom useEffect hook that only triggers on updates, not on initial mount
|
4 | * Idea stolen from: https://stackoverflow.com/a/55075818/1526448
|
5 | * @param {()=>void} effect the function to call
|
6 | * @param {Array<any>} dependencies the state(s) that fires the update
|
7 | */
|
8 | export function useUpdateLayoutEffect(effect, dependencies = []) {
|
9 | const isInitialMount = useRef(true);
|
10 | useLayoutEffect(() => {
|
11 | if (isInitialMount.current) {
|
12 | isInitialMount.current = false;
|
13 | }
|
14 | else {
|
15 | effect();
|
16 | }
|
17 | }, dependencies);
|
18 | }
|
19 | //# sourceMappingURL=useUpdateLayoutEffect.js.map |
\ | No newline at end of file |