Skip to content

Commit 672393e

Browse files
committed
fix: add default props to useTransition
1 parent 509d58c commit 672393e

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

packages/core/src/useTransition.tsx

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ import { is, toArray, useForceUpdate, useOnce, each, OneOrMore } from 'shared'
99
import { now } from 'shared/globals'
1010

1111
import { callProp, interpolateTo } from './helpers'
12-
import { SpringHandle } from './types/spring'
12+
import { SpringHandle, SpringProps } from './types/spring'
13+
import { DEFAULT_PROPS, DefaultProps } from './SpringValue'
1314
import { Controller } from './Controller'
1415

1516
// TODO: convert to "const enum" once Babel supports it
@@ -113,6 +114,13 @@ export function useTransition<T>(data: OneOrMore<T>, props: any, deps?: any) {
113114
// Expired transitions use this to dismount.
114115
const forceUpdate = useForceUpdate()
115116

117+
const defaultProps = {} as DefaultProps
118+
each(DEFAULT_PROPS, prop => {
119+
if (/function|object/.test(typeof props[prop])) {
120+
defaultProps[prop] = props[prop]
121+
}
122+
})
123+
116124
// Generate changes to apply in useEffect.
117125
const changes = new Map<Transition<T>, Change>()
118126
each(transitions, (t, i) => {
@@ -144,20 +152,21 @@ export function useTransition<T>(data: OneOrMore<T>, props: any, deps?: any) {
144152
}
145153

146154
// The payload is used to update the spring props once the current render is committed.
147-
const payload: any = {
155+
const payload = {
156+
...defaultProps,
148157
// When "to" is a function, it can return (1) an array of "useSpring" props,
149158
// (2) an async function, or (3) an object with any "useSpring" props.
150159
to: to = callProp(to, t.item, i),
151160
from: callProp(from, t.item, i),
152161
delay: delay += trail,
153-
config: callProp(props.config, t.item, i),
162+
config: callProp(props.config || defaultProps.config, t.item, i),
154163
...(is.obj(to) && interpolateTo(to)),
155-
}
164+
} as SpringProps
156165

157166
const { onRest } = payload
158-
payload.onRest = (values: any) => {
167+
payload.onRest = result => {
159168
if (is.fun(onRest)) {
160-
onRest(values)
169+
onRest(result)
161170
}
162171
if (t.phase == LEAVE) {
163172
t.expiresBy = now() + expires

0 commit comments

Comments
 (0)