import React, {Component} from 'react';
import {Text, View, TouchableOpacity} from 'react-native';
export default class Parent extends Component {
render() {
return(
<View>
<Child onRef={this.onRef} />
<TouchableOpacity onClick={this.click} >
<Text>click</Text>
</View>
)
}
onRef = (ref) => {
this.child = ref
}
click = (e) => {
this.child.myName()
}
}
class Child extends Component {
componentDidMount(){
this.props.onRef(this)
}
myName = () =>{
alert(11111111111111)
}
render() {
return (<View></View>)
}
}
网友评论