【问题标题】:material-table overriding pagination component causing warnings材料表覆盖分页组件导致警告
【发布时间】:2021-09-02 08:09:21
【问题描述】:

enter code here我正在尝试覆盖材料表中的分页组件。我添加的功能运行良好 - 但是我在控制台中收到警告。警告如下。

Material-UI:提供给 classes 属性的键 selectRoot 不是 在 MTablePaginationInner 中实现。您只能覆盖其中一个 以下:根。

Material-UI:提供给 classes 属性的键 caption 不是 在 MTablePaginationInner 中实现。您只能覆盖其中一个 以下:根

这里是material-ui表的代码片段

        <MaterialTable 
            columns={columns} 
            data={invoices} 
            icons={IconsForMaterialTable}
            options={{ paging:true}}
            components={{
                Pagination: (subProps) => {
                    return <Box display="flex" justifyContent="flex-end"> <Box width="260px" justifyContent="flex-end">
                        <MTablePagination {...subProps} count={pageCount} onChangePage={(e, page) => setPage(page)} page={page} rowsPerPage={rowsPerPage}/>
                    </Box></Box>
                }}}
        />

【问题讨论】:

    标签: reactjs material-ui material-table


    【解决方案1】:

    您看到的警告告诉您,您正在将一个名为 classes 的 prop 传递给 MTablePagination 组件,而 classes 对象如下所示,例如:

    const classes = {
      root: "some_class_name",
      selectRoot: "another_class_name",
      caption: "one_more_class_name"
    }
    

    MTablePagination使用很少的类属性,如selectRootcaption,而是仅使用root 属性(可以在source-code 中看到)。 p>

    因此,您可以安全地忽略这些警告,或编写类似的内容将其删除:

    components={{
      Pagination: (subProps) => {
          return <Box display="flex" justifyContent="flex-end"> <Box width="260px" justifyContent="flex-end">
              <MTablePagination {...subProps} classes={{root: subProps.classes.root}} /* Rest of the code, removed for brevity.*/ />
          </Box></Box>
      }}}
                                               ^^^^ Passing classes
    

    【讨论】:

    • 完美运行 - 非常感谢。很棒的解释
    猜你喜欢
    • 2022-09-23
    • 2021-02-23
    • 2015-02-26
    • 2020-05-16
    • 1970-01-01
    • 2021-06-08
    • 2021-04-12
    • 2020-12-05
    • 2021-06-12
    相关资源
    最近更新 更多