react-spring and typescript not callable 错误

react-spring and typescript not callable error

我无法做出反应的最简单示例-spring 工作:

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

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

    return (
        <Canvas />
    )
}

它给了我这个:

Uncaught TypeError: setSpring is not a function

嗯,它适用于 react-spring v9.0.0 beta。

这里有更多的讨论:https://github.com/pmndrs/react-spring/issues/1359

当前的解决方法:使用 setSpring.current[0].start() 而不是 setSpring()