使用 react reorder 将函数传递给子组件
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()
的子组件中使用
我无法将函数传递给 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()