I want to create components dynamically with custom Refs , and I want to use those refs and use with functionalities like measure() etc.
I created following code
var elems = [];
const CarousalLoop = (props) => {
var links = [
{ name: 'america' },
{ name: 'canada' },
{ name: 'norway' },
{ name: 'bahamas' }
];
links.forEach((val, index) => {
elems[val.name]= useRef(null);
});
const listItems = links.map((link) =>
<CustomCarousel ref={elems[link.name]} category={link.name}/>
);
return (
<View style={{backgroundColor:"white"}}>
{listItems}
</View>
);
}
For example I want to access the compenents using elems["america"] and use it later. but I get following error.
Warning: Function components cannot be given refs. Attempts to access this ref will fail. Did you mean to use React.forwardRef()?