Storing non-state variables in functional components

后端 未结 4 1121
梦谈多话
梦谈多话 2020-12-25 10:45

Below are two React Components that do almost the same thing. One is a function; the other is a class. Each Component has an Animated.Value with an asy

4条回答
  •  悲&欢浪女
    2020-12-25 11:21

    You can use useRef hook (it's the recommended way stated in docs):

    • Declaring variable: const a = useRef(5) // 5 is initial value
    • getting the value: a.current
    • setting the value: a.current = my_value

提交回复
热议问题