失败的道具类型:Material-UI:TablePagination 的页面道具超出范围

kha*_*umi 3 reactjs material-ui

由于分页问题,​​我收到警告错误。我正在使用 Material Ui 并且有搜索功能,问题是当我转到第 2 页并尝试搜索某些内容时出现以下错误

Failed prop type: Material-UI: the page prop of a TablePagination is out of range (0 to 0, but page is 1)
Run Code Online (Sandbox Code Playgroud)

当前表分页代码是

<TablePagination
             onClick = {handleDrawerClose}
             rowsPerPageOptions={[5, 20, 50]}
             component="div"
             count={userManagers && userManagers.length}
             rowsPerPage={rowsPerPage}
             page={page}
             onChangePage={handleChangePage}
             onChangeRowsPerPage={handleChangeRowsPerPage}
            />

the userManagers is the array containing all the data 

Run Code Online (Sandbox Code Playgroud)

pco*_*tra 11

我知道这个问题很老了,但这种情况正在发生,因为当页面渲染时(在获取数据之前),count 属性值等于 0。

为了解决这个问题,我只是在计数为 0 时将值 0 赋予 page 属性。

<TablePagination
    rowsPerPageOptions={[20]}
    colSpan={4}
    count={count}
    rowsPerPage={itemsPerPage}
    page={!count || count <= 0 ? 0 : page}
    SelectProps={{
      inputProps: {
         'aria-label': 'rows per page',
      },
      native: true,
    }}
    onPageChange={handleChangePage}
 />
Run Code Online (Sandbox Code Playgroud)