You are basically causing a stack overflow.
You are calling a setState
inside a render, but, because the setState
dispatch another render, your code is causing an infinite loop.
You need to stop calling this.setState
every render.
In your case, you don't need to put li inside the component's state, you can simply render {li}
.
pagincationScript = (totalPages, page) => {
let li = []
for(let i = 1; i < totalPages; i++) {
li.push(this.liTags(i))
}
if(page > 1 && page < totalPages) {
return(
<React.Fragment>
<li className="Btn Previous"><span><i>←</i>Previous</span></li>
{li}
<li className="Btn Previous"><span><i>→</i>Next</span></li>
</React.Fragment>
)
}
}
But, if you need it to be inside the state, you should move the code that populates this.state.li
to a lifecycle method, like componentDidUpdate
(or useEffect, if you are using hooks).
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…