第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

React setState 不符合直覺

React setState 不符合直覺

慕妹3146593 2019-03-20 17:19:14
我們說setState是批量更新但是下面代碼顯示的star是3有誰知道為什么嗎?import React, { Component } from 'react';class App extends Component {    constructor(props) {        super(props);        this.timer = null;        this.state = { star: 0 };    }        componentDidMount() {        this.timer = setTimeout(() => {            this.setState({ num: this.state.star + 1 });            this.setState({ num: this.state.star + 1 });            this.setState({ num: this.state.star + 1 });        }, 5000);    }        render() {        return <div>{this.state.star}</div>;    }        componentWillUnmount() {        clearTimeout(this.timer);    }}export default App;
查看完整描述

2 回答

?
慕田峪9158850

TA貢獻1794條經(jīng)驗 獲得超8個贊

setState本身是異步的,會積累到一定程度給你更新狀態(tài),并不是馬上set就會馬上change,內(nèi)部有做優(yōu)化的


查看完整回答
反對 回復 2019-04-04
  • 2 回答
  • 0 關(guān)注
  • 382 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號