Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
fix: set the Springs when they're created
useLayoutEffect isnt called when state is set in the hook
  • Loading branch information
joshuaellis committed May 13, 2021
commit 23f7bf62e0872b5ebf2903b15175280ea9b332c1
5 changes: 3 additions & 2 deletions packages/core/src/Controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ export async function flushUpdate(
* until they're given to `setSprings`.
*/
export function getSprings<State extends Lookup>(
ctrl: Controller<State>,
ctrl: Controller<Lookup<any>>,
props?: OneOrMore<ControllerUpdate<State>>
) {
const springs = { ...ctrl.springs }
Expand All @@ -460,6 +460,7 @@ export function getSprings<State extends Lookup>(
})
})
}
setSprings(ctrl, springs)
return springs
}

Expand All @@ -468,7 +469,7 @@ export function getSprings<State extends Lookup>(
* whose key is not already in use.
*/
export function setSprings(
ctrl: Controller,
ctrl: Controller<Lookup<any>>,
springs: SpringValues<UnknownProps>
) {
eachProp(springs, (spring, key) => {
Expand Down
4 changes: 0 additions & 4 deletions packages/core/src/hooks/useSprings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,10 +187,6 @@ export function useSprings(
})

// Update existing controllers.
each(ctrls, (ctrl, i) => {
const values = springs[i]
setSprings(ctrl, values)

each(ctrls.current, (ctrl, i) => {
// Attach the controller to the local ref.
ref?.add(ctrl)
Expand Down
7 changes: 2 additions & 5 deletions packages/core/src/hooks/useTransition.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import {
inferTo,
replaceRef,
} from '../helpers'
import { Controller, getSprings, setSprings } from '../Controller'
import { Controller, getSprings } from '../Controller'
import { SpringContext } from '../SpringContext'
import { SpringRef } from '../SpringRef'
import { TransitionPhase } from '../TransitionPhase'
Expand Down Expand Up @@ -321,13 +321,10 @@ export function useTransition(

useLayoutEffect(
() => {
each(changes, ({ phase, springs, payload }, t) => {
each(changes, ({ phase, payload }, t) => {
const { ctrl } = t
t.phase = phase

// Save any springs created this render.
setSprings(ctrl, springs)

// Attach the controller to our local ref.
ref?.add(ctrl)

Expand Down