React,this.setState data update

after I update the value of currentType in this method, I use currentType as a parameter to adjust the interface in the fetchQuestionIdList function, but each time currentType is the value I updated last time. Choose 2 to transmit 1, 3 to transmit 2, and 4 to transmit 3.
is there any way to solve this delay? Or should I not have used it as a parameter in this way, but defined other variables to hold the value of my choice? Is this.setState just for re-rendering?

 onClickItemType=(item)=>{
    this.setState({
        currentType:{
            code:item.code,
            name:item.name
        },
        isShowTypeList: false
    })
    this.fetchQuestionIdList(this.state.navigationCode)
}

fetchQuestionIdList = async (tfcode) => {
    let params = {
        navigationCode: tfcode,
        typeCode: currentType.code,
        diffCode: currentDiff.code,
        contentFinalFlag: true,
        thirdpartyType: 1
    }
    let systemQuestions = await matchExcerciseApi.getQuestionList(params) || {}
}
Mar.30,2021

The second parameter passed by

this.setState is a callback function, so state is the updated

.
  

this.setState is executed asynchronously, and you need to get the updated value in its callback function.

Menu