Skip to content

Commit 9416f26

Browse files
committed
fix: only replace start func on ref if theres no propsFn
resolves #1810
1 parent 643b4a9 commit 9416f26

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

packages/core/src/hooks/useTrail.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,5 +76,33 @@ export function useTrail(
7676
}
7777
return result
7878
}
79+
80+
/**
81+
* Overwrite the start function so it runs our
82+
* specific trail-making way
83+
* WARNING: we don't want to replace the `start` function
84+
* if the props are fn, it will cause an error.
85+
* See: https://github.com/pmndrs/react-spring/issues/1810
86+
* But we need this to be done for:
87+
* https://github.com/pmndrs/react-spring/issues/1512
88+
*/
89+
ref['start'] = (propsArg?: object | ControllerUpdateFn) => {
90+
const results: AsyncResult[] = []
91+
92+
each(ref.current, (ctrl, i) => {
93+
const props = is.fun(propsArg) ? propsArg(i, ctrl) : propsArg
94+
95+
const parent = ref.current[i + (reverse ? 1 : -1)]
96+
97+
if (parent) {
98+
results.push(ctrl.start({ ...props, to: parent.springs }))
99+
} else {
100+
results.push(ctrl.start({ ...props }))
101+
}
102+
})
103+
104+
return results
105+
}
106+
79107
return result[0]
80108
}

0 commit comments

Comments
 (0)