I don't understand the behavior of react's setState.


                {this.state.count}
                <button onClick={this.add}>click</button>
            </div>
        );
    }
}

export default App;

according to official documents, repeating setState count: this.state.count + 1 is only added once

but this problem does not exist with count: PPthis.state.count.

can someone tell me what"s going on

Sep.10,2021

React doesn't update this.state.count until the component is re-rendered

so every time this.setState ({count: this.state.count + 1}) is executed, this.state.count is 0, and the final result of setState is 1; while this.setState ({count: PPthis.state.count}) each time this.state.count increases by + 1, and the final result of setState is the result of this.state.count .


PPthis.state.count

this code is equivalent to

this.state.count = this.state.count + 1
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e59f81-4555f.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e59f81-4555f.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?