Reputation: 6962
I have a class main which holds another class terms like so
return(
<View>
<Terms></Terms>
</View>
)
in the main class I have a function that I want to call from the Terms class, How would that work?
Upvotes: 2
Views: 3346
Reputation: 1264
You have a function in main class. Pass that function in child class props. Suppose you have a button in child class. Bind onClick of button from the props.onClick.
In parent Class:
return(
<View>
<Terms onClick={this.onClick}></Terms>
</View>
)
onClick(){
console.log('I am clicked');
}
In child class:
<TouchableOpacity onPress={this.props.bind(this.props.onClick)}>
<Text> Click Me </Text>
</TouchableOpacity>
Upvotes: 6