I have in my state:
state = {
validationButton: {
button1: false
}
}
componentDidMount(){
//....
this.check(1)
this.check(2)
}
check(Number){
let today = new Date()
// I call my api to see if exists document with the number
db.get(`${Number}:${today}`)
.then( (doc) => {
//after that I found document:
// * this is what I would to do *
this.setState((this.state.validationButton[`button${Number}`] = true))
})
}
But I receive the error message:
Invariant Violation: setState(...): takes an object of state variables to update or a function which returns an object of state variables.
How can I do to set to true?