( data: unknown, props: UseTransitionProps | (() => any), deps?: any[] )
| 71 | : never |
| 72 | |
| 73 | export function useTransition( |
| 74 | data: unknown, |
| 75 | props: UseTransitionProps | (() => any), |
| 76 | deps?: any[] |
| 77 | ): any { |
| 78 | const propsFn = is.fun(props) && props |
| 79 | |
| 80 | const { |
| 81 | reset, |
| 82 | sort, |
| 83 | trail = 0, |
| 84 | reverse = false, |
| 85 | expires = true, |
| 86 | exitBeforeEnter = false, |
| 87 | onDestroyed, |
| 88 | ref: propsRef, |
| 89 | config: propsConfig, |
| 90 | }: UseTransitionProps<any> = propsFn ? propsFn() : props |
| 91 | |
| 92 | // Return a `SpringRef` if a deps array was passed. |
| 93 | const ref = useMemo( |
| 94 | () => (propsFn || arguments.length == 3 ? SpringRef() : void 0), |
| 95 | [] |
| 96 | ) |
| 97 | |
| 98 | // Every item has its own transition. |
| 99 | const items = toArray(data) |
| 100 | const transitions: TransitionState[] = [] |
| 101 | |
| 102 | // The "onRest" callbacks need a ref to the latest transitions. |
| 103 | const usedTransitions = useRef<TransitionState[] | null>(null) |
| 104 | const prevTransitions = reset ? null : usedTransitions.current |
| 105 | |
| 106 | useIsomorphicLayoutEffect(() => { |
| 107 | usedTransitions.current = transitions |
| 108 | }) |
| 109 | |
| 110 | useOnce(() => { |
| 111 | /** |
| 112 | * If transitions exist on mount of the component |
| 113 | * then reattach their refs on-mount, this was required |
| 114 | * for react18 strict mode to work properly. |
| 115 | * |
| 116 | * StrictMode's simulated unmount detaches the controller from its ref but |
| 117 | * leaves `ctrl.ref` set, so we reset it here to let the commit phase's |
| 118 | * `replaceRef` reattach an *injected* ref. We must NOT assign the local |
| 119 | * `ref` to `ctrl.ref` — that would make a function/deps-form transition |
| 120 | * defer its enter animation as if a ref were injected (see #2287). |
| 121 | * |
| 122 | * See https://github.com/pmndrs/react-spring/issues/1890 |
| 123 | */ |
| 124 | |
| 125 | each(transitions, t => { |
| 126 | ref?.add(t.ctrl) |
| 127 | t.ctrl.ref = undefined |
| 128 | }) |
| 129 | |
| 130 | // Destroy all transitions on dismount. |
searching dependent graphs…