Calling setState in a loop only updates state 1 time

前端 未结 5 2244
故里飘歌
故里飘歌 2020-11-27 21:56

Is there a reason that calling setSate() in a loop would prevent it from updating the state multiple times?

I have a very basic jsbin that highlights th

5条回答
  •  青春惊慌失措
    2020-11-27 21:57

    I had the same problem. But tried with a little different approach.

    iterateData(data){
      //data to render
       let copy=[];
       for(let i=0;) 
        }
        this.setState({
          setComp:copy
        });
     }
     render(){
       return(
         
    {this.state.setComp}
    ); }

    I hope this helps.

提交回复
热议问题