父組件向子組件傳輸用prop,那如果子組件向父組件傳輸怎么傳呢子組件通過click事件點擊,把回調里面的flag變量里面值想傳給父組件,怎么傳呢classChild_1extendsReact.Component{//子組件constructor(props){super(props);this.state={getName:this.props.name,getAge:this.props.age,}}click=()=>{letflag='test';}render(){const{getName,getAge}=this.state;return({`姓名:${getName}`}{`年齡:${getAge}`}clickme)}}exportdefaultChild_1;importChild_1from'./Child_1';classParentextendsReact.Component{//父組件constructor(props){super(props);this.state={}}componentDidMount(){}render(){return()}}exportdefaultParent;
2 回答

哈士奇WWW
TA貢獻1799條經驗 獲得超6個贊
傳回調函數。在父組件里寫個函數change(){}然后通過props傳給子組件,再在子組件的click函數里調用this.props.change()這種東西react的官方文檔里都有。
添加回答
舉報
0/150
提交
取消