Javascript ReactJS:setState在状态对象上

Javascript ReactJS:setState在状态对象上,javascript,reactjs,Javascript,Reactjs,我在我的州有: 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}:${tod

我在我的州有:

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))
})
}
但我收到了错误消息:

不变冲突:setState(…):获取要更新的状态变量对象或返回状态变量对象的函数


如何设置为true?

setState
应该设置一个对象:

this.setState({ validationButton: {[`button${Number}`]: true });

setState
应获取要设置的对象:

this.setState({ validationButton: {[`button${Number}`]: true });
我相信你能做到:

this.setState({validationButton:{[`button${Number}`]:true});
我相信你可以做到:

this.setState({validationButton:{[`button${Number}`]:true});