React-spring: Why is the onFrame props gone for useSpring?

Created on 13 Apr 2020  路  5Comments  路  Source: pmndrs/react-spring

It existed in version 9.0.0 beta34 and was in good use, but it seems to have been removed from canary version. If there is no special reason, it would be good to save it again. Or is there another way to work with similar 'onFrame'?

question v9

Most helpful comment

Yeah, renamed to onChange because it may be called outside the requestAnimationFrame loop. For example, if you call the set method of a value:

const lastValue = useRef()

const { foo } = useSpring({
  foo: flag ? 1 : 0,
  onChange: ({ foo }) => {
    lastValue.current = foo
  }
})

useEffect(() => {
  foo.set(2)
  assert(lastValue.current == 2)
})

All 5 comments

oh, I found 'onChange'..

Yeah, renamed to onChange because it may be called outside the requestAnimationFrame loop. For example, if you call the set method of a value:

const lastValue = useRef()

const { foo } = useSpring({
  foo: flag ? 1 : 0,
  onChange: ({ foo }) => {
    lastValue.current = foo
  }
})

useEffect(() => {
  foo.set(2)
  assert(lastValue.current == 2)
})

@aleclarson As I noticed, onChange returns a SpingValue and not,say, a primitive.

How we use onChange to achieve the same thing with onFrame so that we can, for example, scroll a viewport?

@phaistonian Sorry, I don't understand. What have you tried so far? Code plz.

@aleclarson Figured this out - thank you.

Somehow - the excellent documentation - got me a bit confused.

Kudos for the work you did, btw - it's sublime, by all means.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

localjo picture localjo  路  3Comments

cmmartin picture cmmartin  路  3Comments

MaximeDenuit picture MaximeDenuit  路  4Comments

eDubrovsky picture eDubrovsky  路  3Comments

fortezhuo picture fortezhuo  路  3Comments