如何根据数据更新状态前后调用函数-React-redux

问题描述:

我有一个下拉菜单选择传奇被调用,并且必须使用相同的组件.saga 被调用,唯一没有发生的事情是 set 状态在 saga 调用之前更新,因此组件从不更新数据.

I've a drop down on select the saga is called and the same component must be used. The sagas are called the only thing not happening is the set state is updating before the saga call therefore the component never updates the data.

            recievedChangeValue=(selectVal)=>{
                console.log(selectVal)
                if(selectVal==='Yearly'){
                     this.props.getYearlySales() **//call to saga**
                     this.setState({salesData:this.props.yearlySales}) **//it updates before the called saga ends**                         
                 }
                if(selectVal==='Decade'){ 
                    this.props.getSales()**//call to saga**
                    this.setState({salesData:this.props.dataSales})   **//it updates before the called saga ends**                                           
                }
            }

我知道回调,但这里的状态只能在传奇调用之后更新.我从过去一天开始就在处理它,我不知道必须做什么.任何帮助表示赞赏.请让我知道我哪里出错了.

I know the callback but here the state must be updated only after the saga call.I'm working onto it since past day I've no idea as to what has to be done. Any help is appreciated.Please lemme know as to where i'm going wrong.

 recievedChangeValue=(selectVal)=>{
this.setState({selectedSalesData:selectVal},
  ()=>{
    if(selectVal==='Yearly'){
        this.props.getYearlySales() 
    }
    if(selectVal==='Decade'){ 
        this.props.getSales()
    }
  }
)

}

以下是我在render中写的

The following I wrote in render

   let SalesData=this.handleSalesData(selectedSalesData)//calls on selecteddata and it works like a charm