I am attempting to create an array of JSX Elements out of an array.map() lambda, but when setting and storing a ref for each of them, those refs return as objects with their "current" as null.
If we look at the source of ViewPager (react-native-viewpager), we will see children={childrenWithOverriddenStyle(this.props.children)} (line 182). If we dig into the childrenWithOverriddenStyle method, we will see that it is actually "cloning" the children being passed in via React.createElement.
While this doesn't fix the problem, this at least answers the question of why the refs are null in your Map. It actually may be worth creating an issue for the library in order to swap it to React.cloneElement, since cloneElement will preserve the ref.
Environment info
react-native info output:
System:
OS: Windows 10 10.0.18362
CPU: (8) x64 Intel(R) Core(TM) i7-9700K CPU @ 3.60GHz
Memory: 8.33 GB / 31.93 GB
Binaries:
Node: 12.16.2 - C:\Program Files\nodejs\node.EXE
Yarn: 1.22.4 - C:\Program Files (x86)\Yarn\bin\yarn.CMD
npm: 6.14.4 - C:\Program Files\nodejs\npm.CMD
Watchman: Not Found
SDKs:
Android SDK: Not Found
IDEs:
Android Studio: Not Found
Languages:
Java: Not Found
Python: 3.7.6
npmPackages:
@react-native-community/cli: Not Found
react: ~16.11.0 => 16.11.0
react-native: https://github.com/expo/react-native/archive/sdk-38.0.2.tar.gz => 0.62.2
npmGlobalPackages:
*react-native*: Not Found
Library version: x.x.x
Steps to reproduce
Create a Map/Array of React.RefObjects.
Use an arrow function to create an array of JSX elements
Within the arrow function, create and set a ref for each JSX Element, and store it in the Map/Array
Try to use any of the refs later and all of their "current" properties will be "null"
Describe what you expected to happen:
I expect the refs passed to the JSX Elements to be valid refs
Bug report
Summary
I am attempting to create an array of JSX Elements out of an array.map() lambda, but when setting and storing a ref for each of them, those refs return as objects with their "current" as null.
More information from this post: https://stackoverflow.com/questions/63651084/map-of-refs-current-is-always-null?noredirect=1#comment112557125_63651084
Environment info
react-native info
output:Library version: x.x.x
Steps to reproduce
Describe what you expected to happen:
Reproducible sample code