@@ -9,7 +9,8 @@ import { is, toArray, useForceUpdate, useOnce, each, OneOrMore } from 'shared'
9
9
import { now } from 'shared/globals'
10
10
11
11
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'
13
14
import { Controller } from './Controller'
14
15
15
16
// TODO: convert to "const enum" once Babel supports it
@@ -113,6 +114,13 @@ export function useTransition<T>(data: OneOrMore<T>, props: any, deps?: any) {
113
114
// Expired transitions use this to dismount.
114
115
const forceUpdate = useForceUpdate ( )
115
116
117
+ const defaultProps = { } as DefaultProps
118
+ each ( DEFAULT_PROPS , prop => {
119
+ if ( / f u n c t i o n | o b j e c t / . test ( typeof props [ prop ] ) ) {
120
+ defaultProps [ prop ] = props [ prop ]
121
+ }
122
+ } )
123
+
116
124
// Generate changes to apply in useEffect.
117
125
const changes = new Map < Transition < T > , Change > ( )
118
126
each ( transitions , ( t , i ) => {
@@ -144,20 +152,21 @@ export function useTransition<T>(data: OneOrMore<T>, props: any, deps?: any) {
144
152
}
145
153
146
154
// The payload is used to update the spring props once the current render is committed.
147
- const payload : any = {
155
+ const payload = {
156
+ ...defaultProps ,
148
157
// When "to" is a function, it can return (1) an array of "useSpring" props,
149
158
// (2) an async function, or (3) an object with any "useSpring" props.
150
159
to : to = callProp ( to , t . item , i ) ,
151
160
from : callProp ( from , t . item , i ) ,
152
161
delay : delay += trail ,
153
- config : callProp ( props . config , t . item , i ) ,
162
+ config : callProp ( props . config || defaultProps . config , t . item , i ) ,
154
163
...( is . obj ( to ) && interpolateTo ( to ) ) ,
155
- }
164
+ } as SpringProps
156
165
157
166
const { onRest } = payload
158
- payload . onRest = ( values : any ) => {
167
+ payload . onRest = result => {
159
168
if ( is . fun ( onRest ) ) {
160
- onRest ( values )
169
+ onRest ( result )
161
170
}
162
171
if ( t . phase == LEAVE ) {
163
172
t . expiresBy = now ( ) + expires
0 commit comments