javascript - 如何将组件作为道具传递给反应中的道具?
问题描述
我正在使用来自 dev-express 的 react-grid 库,库中有一个 Table 组件,我们可以将 Cell 组件传递给该组件,在 CustomCell 内部,我正在使用 Material UI 中的菜单
<Table
columnExtensions={tableColumnExtensions}
cellComponent= {CustomCell}
/>
在上述情况下,菜单工作正常,
但我想将道具传递给这个组件,我尝试了以下
<Table
columnExtensions={tableColumnExtensions}
cellComponent= {(props)=><CustomCell {...props} someFunc={this.someFunc} />}
/>
在这种情况下,菜单不起作用,我想知道是否有另一种方法来实现第二种情况。
解决方案
你可以这样做withProps
:
const CustomCellWithSomeFunc = withProps({someFunc: this.someFunc.bind(this)})(CustomCell);
<Table
columnExtensions={tableColumnExtensions}
cellComponent= {CustomCellWithSomeFunc/>}
/>
推荐阅读
- linux - crontab 无法识别命令
- kendo-ui - 角度的 Kendo UI - 网格移位单击以选择行
- discord - Discord.js - 设置频道描述
- i2c - I2C LCD显示奇怪的字符
- mysql - 用户定义的函数只返回 NULL
- google-apps-script - 基于谷歌表格中的多行循环脚本
- sql - 存储过程运行了多天......我的语法是否有问题导致它无限循环?
- php - 根据一对多关系的值对集合进行排序
- sql-server - HashiCorp 根数据库凭证轮换与 SQL Server
- node.js - 如何在 mongodb 中找到整数值的 $regex?