父组件调用子组件方法
父组件中调用子组件的getTree方法
父组件
setFormValue=()=>{
this.TreeList.getTree
}
<TreeList onSelect={this.setFormValue} onRef={(ref) => { this.TreeList = ref }} />
子组件
componentDidMount = () => {
this.props.onRef(this);
this.getTree()
}
getTree=()=>{
}
子组件调用父组件方法
子组件中调用父组件的setId方法
父组件
<NavBarX
item={item}
current={current}
getBatchDetails={(id) => this.getBatchDetails(0, id)}
setId={(id, callback) => this.setState({ id }, callback)}
onRef={this.onNavBarXRef}
/>
子组件
this.props.setId(prePageId, () => {
getBatchDetails(prePageId)
})