Reputation: 51
showConfirmationMessage = () => {
Alert.alert(
'Confirmation Message',
'Proceed?',
[
{text: 'BACK', onPress: () => this.setState({ loading: false })},
{text: 'CONFIRM', onPress: () => this._getTaskData()},
],
{cancelable: false},
);
}
_getTaskData = () => {
console.log(this.component2.getValue());
}
This is how I called the function. When I called _getTaskData() directly, it works fine. But, when I call it like above (through the confirmation message), it gives the error.
Upvotes: 0
Views: 178
Reputation: 2684
Write a function inside Component2
to get your input values:
getValue = () => {
return this.state.inputValue;
}
and set a reference for your Component2
inside Component1
<Component2 ref={r => this.component2 = r} />
Now you can get your input value with your this.component2
reference
this.component2.getValue();
Upvotes: 1