Search code examples
react-spring

react-spring and typescript not callable error


I am unable to make the simplest example of react-spring work:

import { useSpring } from 'react-spring/three'

export const myComponent = () => {
    const [spring, setSpring] = useSpring(() => ({ xpos: 0 }))
    setSpring({xpos: 10})

    return (
        <Canvas />
    )
}

It gives me this:

Uncaught TypeError: setSpring is not a function


Solution

  • There's more discussion on this here: https://github.com/pmndrs/react-spring/issues/1359

    Current work-around: use setSpring.current[0].start() rather than setSpring()