You need to wrap MyComponent around React.forwardRef()
e.g.
const MyComponent = React.forwardRef((props, ref) => {
return (
<View ref={ref}> // using the ref
// your component
</View>
})
Also, ref='_my_refs' doesn't work because it's a legacy ref, you should use React.createRef() for class components or useRef for functional component.
You can check for more details in the docs.
e.g.
class ParentComponent extends React.Component {
constructor(props) {
super(props);
this._my_refs = React.createRef();
}
render(){
return (
// ...
<MyComponent
ref={this._my_refs}
...
/>
)
}
}
OR
const ParentComponent = props => {
const myRef = React.useRef()
return (
// ...
<MyComponent
ref={myRef}
...
/>
)
}
If you pass a ref to a functional component and it isn't wrapped around React.forwardRef, it will give you the error
Warning: Function components cannot be given refs. Attempts to access this ref will fail. Did you mean to use React.forwardRef()?
And this means MyComponent is a functional component and isn't wrapped around React.forwardRef.