[英]How to pass React Component prop to child function using {children}?
[英]pass function to child component using react reorder
我堅持將函數傳遞給Reorder的子組件
父組件(代碼的某些部分)
import Reorder from 'react-reorder';
constructor() {
super();
this._bind(
'_changeStatusReorder'
);
this.state = {
status: true
};
}
_changeStatusReorder() { //my function
console.log('_changeStatusReorder');
this.setState({
status: false
});
}
return (
<div className={styles.main}>
<Reorder
...
...
sharedProps={{changeStatus: this._changeStatusReorder}} //pass function to props
/>
</div>
);
和子組件
_handleMouseDown() {
const {sharedProps: {changeStatus}} = this.props;
console.log(sharedProps); //try to see at console
setTimeout(() => {
},0);
}
我在控制台中得到了“Uncaught ReferenceError:sharedProps is not defined”,所以我不知道我錯了什么。 我無法解決它。
嘗試使用sharedProps={this._changeStatusReorder}
。 並使用this.props.sharedProps()
在子組件中使用
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.