3

Description

Cannot create an array of refs using useAnimatedRef. Below I have mentioned how one can create an array of refs using a traditional useRef but for some reason useAnimatedRef does not recognize arrays. Even when an empty array is placed inside such as const refArray = useAnimatedRef([]) one cannot use .push or any other array methods on the ref. This is a problem because there are times where we need to create arrays of refs. Is there a different approach to making an array of refs that I’m not aware of? I tried plenty of work arounds but none work.

Code example

code bellow does not work since the array is not recognized. const refArray = useAnimatedRef([]) refArray.current.push(SOME_ITEM)

This is how one would create an array of refs using traditional useRef. This obviously does not work since there is no createRef equivalent for useAnimatedRef() const refArray = useRef([...Array()].map(() => createRef()))

Package versions

  • React: 16.13.1
  • React Native: 0.63.4
  • React Native Reanimated:
  • 2.0.0-rc.0 NodeJS: 12.3.0
haibert
  • 148
  • 1
  • 12

0 Answers0