I have a class component in a reactjs project. The following code segment works fine. But inside the map function, I am not able to access the state variables. I am getting the below error,
TypeError: Cannot read properties of undefined (reading 'state')
Even console.log(this.state.total);
didn't work inside the map function.
constructor(props) {
super(props);
this.state = {
page: 2,
total: 0,
};
}
<Pagination>
{this.state.total > 0 ?
Array(Math.ceil(this.state.total / 10)).fill(0).map(function (object, i) {
return <Pagination.Item active={false} key={i}>{i + 1}</Pagination.Item>
}).bind(this) : null}
</Pagination>