In the following code handlePage
always report 30 instead of the index i
. This is not strictly ReactJS related but general JS behavior. What is causing this and how do I fix it?
const handlePage = (x) => {
console.log(x)
}
return (
for(var i = 0; i<30; i++) {
<div onClick={() => handlePage(i)}>{i}</div>
}
)