MCPcopy
hub / github.com/gilbarbara/react-joyride / useLifecycleEffect

Function useLifecycleEffect

src/hooks/useLifecycleEffect.ts:27–512  ·  view source on GitHub ↗
(options: UseLifecycleEffectOptions)

Source from the content-addressed store, hash-verified

25}
26
27export default function useLifecycleEffect(options: UseLifecycleEffectOptions): void {
28 const { addFailure, controls, emitEvent, previousState, props, state, step, store } = options;
29 const { action, index, lifecycle, positioned, scrolling, size, status } = state;
30
31 const previousStep = usePrevious(step) ?? null;
32
33 const lastAction = useRef<Actions | null>(null);
34 const propsRef = useRef(props);
35 const stateRef = useRef(state);
36 const previousStateRef = useRef(previousState);
37 const stepRef = useRef(step);
38 const previousStepRef = useRef(previousStep);
39 const controlsRef = useRef(controls);
40 const pollingRef = useRef<ReturnType<typeof setInterval> | null>(null);
41 const pollingTargetRef = useRef<StepTarget | null>(null);
42 const beforeRef = useRef<{ cancel: () => void } | null>(null);
43
44 propsRef.current = props;
45 stateRef.current = state;
46 previousStateRef.current = previousState;
47 stepRef.current = step;
48 previousStepRef.current = previousStep;
49 controlsRef.current = controls;
50
51 const cleanup = () => {
52 if (pollingRef.current) {
53 clearInterval(pollingRef.current);
54 pollingRef.current = null;
55 }
56
57 pollingTargetRef.current = null;
58
59 if (beforeRef.current) {
60 beforeRef.current.cancel();
61 beforeRef.current = null;
62 }
63 };
64
65 // Effect 1: Action tracking
66 useEffect(() => {
67 if (!previousStateRef.current) {
68 return;
69 }
70
71 const { hasChangedTo } = treeChanges(stateRef.current, previousStateRef.current);
72
73 const isAfterAction = hasChangedTo('action', [
74 ACTIONS.NEXT,
75 ACTIONS.PREV,
76 ACTIONS.SKIP,
77 ACTIONS.CLOSE,
78 ACTIONS.REPLAY,
79 ]);
80
81 const isStaleAfterStart =
82 action === ACTIONS.START &&
83 (lastAction.current === ACTIONS.CLOSE || lastAction.current === ACTIONS.REPLAY);
84

Callers 2

useTourEngineFunction · 0.85

Calls 11

treeChangesFunction · 0.90
logFunction · 0.90
getElementFunction · 0.90
isElementVisibleFunction · 0.90
shouldHideBeaconFunction · 0.90
needsScrollingFunction · 0.90
getMergedStepFunction · 0.90
hasChangedToFunction · 0.85
cleanupFunction · 0.85
hasChangedFunction · 0.85
proceedFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…