【发布时间】:2020-05-04 14:20:57
【问题描述】:
我有多个使用 Cell 函数的 React-Table 列:
在主类中:
Cell: function (props) {
return (
<span>
<ChildClass
id={props.original._id} myemail={this.state.email}
/>
</span>
);
},
所以我得到了错误:TypeError: Cannot read property 'state' of undefined
我想使用 Cell 函数中的状态。
谢谢
【问题讨论】:
-
你不能在功能组件中使用
this.state。 -
你可以在功能组件内部使用
useState钩子来管理状态。 reactjs.org/docs/hooks-state.html -
我的案例有什么例子吗?
-
你能把文件的全部代码贴出来吗?
标签: javascript reactjs function state react-table