parent如何调用child的action,React小技巧

118 阅读1分钟

PATTERN:

class parent componet{
    
    ....
    onClick=e=>{
        this.pullAction();
    }
    ...
    
    
render (){
return(
  <Child pullAction={ pushAction => this.pullAction=pushAction} />
)
}



class Child componet{
    
    componentDidMount(){
      this.props.pullAction(this.method);   
        
    }
}