React setState in a map function

前端 未结 3 1674
渐次进展
渐次进展 2021-01-28 08:44

I cannot wrap my head around the issue below.

The issue relates to the asynchronous setState dimension. Usually I use the callback, but doesn\'t seem appropriate here.

3条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-28 08:56

    Just use second argument in this.setState.

    Second argument is a function that will be called after seting State.

    this.setState({ name:value },() => {this.nameOfTheFunctionYouWantToRunNext() });

提交回复
热议问题