I was trying to count the completed tasks, and the logic should be right I believe, but seems the this.setState({})
is not responding/reached at all, it's not doing anything to the data 'qtySelected' in the this.state({})
since the console.log('ts')
didn't have a result in the console. Anyone knows why, maybe it's some react lifecycle issue?
export class Main extends Component {
constructor(pros) {
super(pros)
this.state = {
tasks: [
{
id: 1,
content: "Sara's doctor and vaccine",
due: '2020-08-29',
completed: false
},
{
id: 2,
content: "Trash bags / facial masks / child allowance",
due: '2020-08-28',
completed: false
},
{
id: 3,
content: "Apply for Portugal nationality",
due: '2020-09-31',
completed: false
},
{
id: 4,
content: "My registeration card",
due: '2020-09-28',
completed: false
},
{
id: 5,
content: "contact ADEM",
due: '2020-12-31',
completed: false
},
{
id: 6,
content: "Pay loan",
due: '2020-09-03',
completed: true
}
],
qtySelected: 0
}
}
componentDidMount() {
this.countSelected = () => {
console.log('ts')
let tasksCompleted = this.state.tasks.filter(task => {
return task.completed === true
})
this.setState({
qtySelected: tasksCompleted.length
})
}
}
render() {
return (
<div>
<table>
<tfoot>
<tr>
<td style={{ whiteSpace: "nowrap" }}>{this.state.qtySelected} selected</td>
</tr>
</tfoot>
</table>
</div>
)
}
}