React Table-单元功能内部的访问状态值

问题描述 投票:0回答:1

我使用Cell函数具有多个React-Table列:

在主班级:

Cell: function (props) {
  return (
    <span>
      <ChildClass
        id={props.original._id} myemail={this.state.email}
      />
    </span>
  );
},

所以我得到了错误:TypeError:无法读取未定义的属性'state'

我想使用该Cell函数内部的状态。

谢谢

javascript reactjs function state react-table
1个回答
0
投票

该函数未获取“ this”,您必须将此函数设为lambda(arrow)函数或需要绑定this。

Cell:(props) => {
  return (
    <span>
      <ChildClass
        id={props.original._id} myemail={this.state.email}
      />
    </span>
  );
},

我希望这对您有用,或者以其他方式共享代码的详细信息。

© www.soinside.com 2019 - 2024. All rights reserved.