React Native: When accessing a component via ref, how do you access methods of that component?

Viewed 23

In my React Native app, I have a component Form1:

class Form1 extends Component {
  function1 = () => {...}
  render() {return(...)}
}

In Form1 I can access function1 via this.function1(). I create an instance of Form1 in another component and pass it the prop var1, which I can access in Form1 via this.props.var1.

<Form1
  ref={ref => {this.form = ref.wrappedInstance}}
  var1="hello"
/>

Here where I set this.form = ref.wrappedInstance in the parent component, I can then access var1 via this.form.props.var1. In other words, ref.wrappedInstance.props exists. However, I can't access function1 the same way; ref.wrappedInstance.function1 doesn't exist.

How can I access function1 in this case?

1 Answers
Related