@@ -122,17 +122,17 @@ export function useSprings(
122122 [ ]
123123 )
124124
125- const ctrls = [ ...state . ctrls ]
125+ const ctrls = useRef ( [ ...state . ctrls ] )
126126 const updates : any [ ] = [ ]
127127
128128 // Cache old controllers to dispose in the commit phase.
129129 const prevLength = usePrev ( length ) || 0
130- const oldCtrls = ctrls . slice ( length , prevLength )
130+ const oldCtrls = ctrls . current . slice ( length , prevLength )
131131
132132 // Create new controllers when "length" increases, and destroy
133133 // the affected controllers when "length" decreases.
134134 useMemo ( ( ) => {
135- ctrls . length = length
135+ ctrls . current . length = length
136136 declareUpdates ( prevLength , length )
137137 } , [ length ] )
138138
@@ -144,7 +144,9 @@ export function useSprings(
144144 /** Fill the `updates` array with declarative updates for the given index range. */
145145 function declareUpdates ( startIndex : number , endIndex : number ) {
146146 for ( let i = startIndex ; i < endIndex ; i ++ ) {
147- const ctrl = ctrls [ i ] || ( ctrls [ i ] = new Controller ( null , state . flush ) )
147+ const ctrl =
148+ ctrls . current [ i ] ||
149+ ( ctrls . current [ i ] = new Controller ( null , state . flush ) )
148150
149151 const update : UseSpringProps < any > = propsFn
150152 ? propsFn ( i , ctrl )
@@ -159,7 +161,7 @@ export function useSprings(
159161 // New springs are created during render so users can pass them to
160162 // their animated components, but new springs aren't cached until the
161163 // commit phase (see the `useLayoutEffect` callback below).
162- const springs = ctrls . map ( ( ctrl , i ) => getSprings ( ctrl , updates [ i ] ) )
164+ const springs = ctrls . current . map ( ( ctrl , i ) => getSprings ( ctrl , updates [ i ] ) )
163165
164166 const context = useContext ( SpringContext )
165167 const prevContext = usePrev ( context )
@@ -169,7 +171,7 @@ export function useSprings(
169171 layoutId . current ++
170172
171173 // Replace the cached controllers.
172- state . ctrls = ctrls
174+ state . ctrls = ctrls . current
173175
174176 // Flush the commit queue.
175177 const { queue } = state
@@ -185,10 +187,7 @@ export function useSprings(
185187 } )
186188
187189 // Update existing controllers.
188- each ( ctrls , ( ctrl , i ) => {
189- const values = springs [ i ]
190- setSprings ( ctrl , values )
191-
190+ each ( ctrls . current , ( ctrl , i ) => {
192191 // Attach the controller to the local ref.
193192 ref ?. add ( ctrl )
194193
0 commit comments