MCPcopy Index your code
hub / github.com/adobe/react-spectrum / useUpdateEffect

Function useUpdateEffect

packages/react-aria/src/utils/useUpdateEffect.ts:17–39  ·  view source on GitHub ↗
(cb: EffectCallback, dependencies: any[])

Source from the content-addressed store, hash-verified

15
16// Like useEffect, but only called for updates after the initial render.
17export function useUpdateEffect(cb: EffectCallback, dependencies: any[]): void {
18 const isInitialMount = useRef(true);
19 const lastDeps = useRef<any[] | null>(null);
20 let cbEvent = useEffectEvent(cb);
21
22 useEffect(() => {
23 isInitialMount.current = true;
24 return () => {
25 isInitialMount.current = false;
26 };
27 }, []);
28
29 useEffect(() => {
30 let prevDeps = lastDeps.current;
31 if (isInitialMount.current) {
32 isInitialMount.current = false;
33 } else if (!prevDeps || dependencies.some((dep, i) => !Object.is(dep, prevDeps[i]))) {
34 cbEvent();
35 }
36 lastDeps.current = dependencies;
37 // eslint-disable-next-line react-hooks/exhaustive-deps
38 }, dependencies);
39}

Callers 4

useComboBoxFunction · 0.90
useCalendarBaseFunction · 0.90
useTableFunction · 0.90

Calls 1

useEffectEventFunction · 0.90

Tested by

no test coverage detected