猿问

react,this.setState数据更新

这个方法中我更新currentType的值以后,在fetchQuestionIdList函数中用currentType作为参数去调接口,但是每次currentType都是我上次更新的值,选2传送1,选3传送2,选4传送3....
有什么方法解决这种延迟?或者我跟本不应该这样用它作为参数,而是定义别的变量保存我选的值?this.setState只是用来重新渲染吗?

 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) || {}}


拉莫斯之舞
浏览 1496回答 1
1回答
随时随地看视频慕课网APP

相关分类

JavaScript
我要回答