I need to filter list of question by category so I decided to add category_id in empty table categories on checkbox change but the table stay empty?
// Définition of state
constructor(props) {
super(props);
this.handleCategoryChange.bind(this)
this.state = {
filters: []
}
}
// Checkbox Categories change
handleCategoryChange (category, e) {
if (e.target.checked) {
this.setState((state) => ({
filters: [[...state.filters], ...[category.id]]
}));
console.log(this.state.filters) // empty
}
}
// Checkbox input
render() {
return (
<div className="form-check mb-2">
<input className="form-check-input" type="checkbox" id={'category-' + this.props.category.id} onChange={(e) => this.handleCategoryChange(this.props.category, e)}/>
<label className="form-check-label" htmlFor="category">
{ this.props.category.name }
</label>
</div>
)
}