首页 > 解决方案 > 如何将组件作为道具传递给反应中的道具?

问题描述

我正在使用来自 dev-express 的 react-grid 库,库中有一个 Table 组件,我们可以将 Cell 组件传递给该组件,在 CustomCell 内部,我正在使用 Material UI 中的菜单

  <Table
        columnExtensions={tableColumnExtensions}
        cellComponent= {CustomCell}
  />

在上述情况下,菜单工作正常,

但我想将道具传递给这个组件,我尝试了以下

 <Table
        columnExtensions={tableColumnExtensions}
        cellComponent= {(props)=><CustomCell {...props} someFunc={this.someFunc} />}
/>

在这种情况下,菜单不起作用,我想知道是否有另一种方法来实现第二种情况。

标签: javascriptreactjsmaterial-ui

解决方案


你可以这样做withProps

const CustomCellWithSomeFunc = withProps({someFunc: this.someFunc.bind(this)})(CustomCell);

<Table
    columnExtensions={tableColumnExtensions}
    cellComponent= {CustomCellWithSomeFunc/>}
/>

推荐阅读