【发布时间】:2021-04-20 21:43:14
【问题描述】:
我正在尝试在 React 中设置页面分页 Material UI,但总是在显示正确元素的 1 秒后重定向到第 1 页。我使用控制台日志,我可以看到切片正在更改 0..1、1..2 和 2..3,但内容没有。
{
this.state.teams
.slice((this.state.page - 1) * itemsPerPage, this.state.page * itemsPerPage)
.map((product,index) => (
<TeamCard
className={stylesMain.TeamCard}
number={this.state.teams[index]}
teamNum={this.state.teamNum[index]}
verified ={this.state.verified[index]}
/>
<Pagination
color="primary"
count={Math.ceil(resultLength/1)}
size="small"
page={this.state.page}
onChange={this.handleChange2}
defaultPage={1}
showFirstButton
showLastButton
/>
constructor(props){
super(props);
this.state = {
teams: [],
page: 1
}
}
handleChange2 = (event, value) => {
this.setState({page: value});
};
componentDidMount() {
this.getTeams();
}
【问题讨论】:
-
请确保共享的示例是minimal reproducible example?目前还没有
标签: javascript reactjs pagination