setState not working with forloop in react function

前端 未结 2 1419
萌比男神i
萌比男神i 2021-01-27 16:09

I am nesting two api calls inside componentDidMount, everything working fine, the only issue I have is the state do not update so I put some console logs to see what\'s going on

2条回答
  •  死守一世寂寞
    2021-01-27 17:05

    You have a couple conflicting processes here that need to get shored up. You don't want to modify state during async actions because internally you will fire off a re-render, so I'd suggest reorganizing a bit. The loaded state is not resolving correctly because you aren't waiting for your subsequent requests to finish. Here is an example:

提交回复
热议问题