鍍金池/ 問答/HTML/ 在react中 在setState方法的回調函數(shù)中能否再次調用setState方

在react中 在setState方法的回調函數(shù)中能否再次調用setState方法?

在componentWillMount中請求數(shù)據(jù)后,將拿到的數(shù)據(jù)setState操作后,在setState回調中能否再用state中的參數(shù)發(fā)起ajax請求后再將拿回的數(shù)據(jù)setState
componentWillMount(){

let appId = this.GetQueryString('appId')
let language = this.GetQueryString('language')
axios.post('/api/language/findAll').then(res=>{
  console.log('0000')
  for(let i=0;i<res.length;i++){
    if(res[i].en==language){
      this.setState({
        language:res[i].pid,
        appId:appId
      },()=>{
        this.queryConfig()
      })
    }
  }
})

}
queryConfig(){

let params={
  appId:this.state.appId,
  lang:this.state.language
}
axios.post('/api/spirit/config',params).then(res=>{
    console.log('第二個請求')
    this.setState({
      custom:res.spirit.custom,
      recommend:res.spirit.recommend,
      strategy:res.spirit.strategy,
    },()=>{console.log('第二次渲染')})
})

};

回答
編輯回答
尕筱澄

可以, 完全沒問題.

render 中調用 setState 才會有問題.

2018年9月3日 18:45