2017-06-21 19 views

答えて

1

あなたは、子コンポーネントへの参照を代入して、

class Parent extends React.Component { 
    callChildFunction =() => { 
     this.child.handleActionParent(); ///calling a child function here 
    } 
    render(){ 
     return (
      <div> 
      {/* other things */} 
      <Child ref={(cd) => this.child = cd}/> 
      </div> 
    ) 
    } 
} 

class Child extends React.Component { 
    handleActionParent =() => { 
     console.log('called from parent') 
    } 
    render() { 
     return (
      {/*...*/} 
    ) 
    } 
} 
のような関数形の親を呼び出すことができます
関連する問題