React shows wrong data. I guess it just dont update. I cant solve this problem for 2 days. Help please. What is wrong here? I tried to fix componentdidmount but unfortunatelly it didn't help
class Table extends React.Component {
constructor(props) {
super(props);
this.state = {data: []}
}
componentDidMount() {
this.data = setInterval(() =>
console.log(this.setState({data})),
this.setState(
fetch('/lk/reports/3/month-ajax')
.then(response => response.json())
.then(data => this.setState({data})))
, 50);
}
componentWillUnmount() {
clearInterval(this.data);
}
render() {
if (this.state.data.length == 0) {
return (<div className="table-wrapper mt-5 d-flex justify-content-center">
<i className="fas fa-spinner fa-3x fa-fw fa-spin"></i>
</div>);
} else {
return (
<table className="table highlight responsive-table">
<thead className="teal lighten-4">
<tr>
<th>{this.state.data.time}</th>
</tr>
</thead>
<tbody>
{this.state.data.kpi.map(item => <tr className={this.activeRow(item)}>
<td>{item.client}</td>
<td>{item.all_incidents}</td>
</tr>)}
</tbody>
</table>
);
}
}
}
Here is full react.js code Thank you!