React Native 渲染错误值未定义,需要一个对象

Shi*_*rma 6 typescript reactjs react-native react-native-reanimated

所以我不知道为什么我会收到这个奇怪的错误,并且我无法找到任何解决方案,所以请帮助我

错误 在此输入图像描述

在此输入图像描述

代码

import React, { useRef, useState } from 'react'
  2 import Animated, { Easing, useAnimatedProps } from 'react-native-reanimated'
  3 import { Path, PathProps } from 'react-native-svg'
  4
  5 interface AnimatedStrokeProps extends PathProps {
  6   progress: Animated.SharedValue<number>
  7 }
  8
  9 const AnimatedPath = Animated.createAnimatedComponent(Path)
 10
 11 const AnimatedStroke = ({ progress, ...pathProps }: AnimatedStrokeProps) => {
 12   const [length, setLength] = useState(0)
 13   const ref = useRef<typeof AnimatedPath>(null)
 14   const animatedProps = useAnimatedProps(() => ({
 15     strokeDashoffset: Math.max(
 16       0,
 17       length - length * Easing.bezier(0.37, 0, 0.63, 1)(progress.value) - 0.1
 18     )
 19   }))
 20
 21   return (
 22     <AnimatedPath
 23       animatedProps={animatedProps}
 24       // @ts-ignore
 25       onLayout={() => setLength(ref.current!.getTotalLength())}
 26       // @ts-ignore
 27       ref={ref}
 28       strokeDasharray={length}
 29       {...pathProps}
 30     />
 31   )
 32 }
 33
 34 export default AnimatedStroke
Run Code Online (Sandbox Code Playgroud)

所以请帮助我,我真的非常需要帮助。

小智 0

更新你的react-native-reanimated版本。在我的例子中,我有react-native-reanimated版本2.3.1并回滚到2.2.4版本。之后我发生了这个错误