React子組件傳遞給父組件的方法

1)redux狀態管理

2)通過refs傳遞,代碼如下所示:

父組件代碼:

<QueryBox ref="queryBox" app={this.app} onSearch={this.onSearch} onCount={this.onCount} />
let QueryBoxInstance = this.refs.queryBox as QueryBox;
QueryBoxInstance.onChange();

3)通過回掉函數傳遞,代碼如下:

父組件

<AddModal
onOk={(score: any, review: any) => this.handleOk(score, review) as any}
onCancel={this.hideModal as any}
loading={this.state.loading}
studentInfo={this.state.studentInfo}
/>

子組件

<Modal
 visible={true}
title="評分"
onOk={()=>{
this.props.onOk(this.state.score,this.state.review)
}}
onCancel={this.props.onCancel}
confirmLoading={this.props.loading}
okText="確認"
className="review"
cancelText="取消"
>

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章