繁体   English   中英

使用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()在子组件中使用

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM