'Why is the output different with React setState()
I don't know why
- When I use
this.setState({count: count+1}Clicking multiple times will only update count once - When I use
this.setState({count: this.setState.count})Each click updates the count - Why different?
class Demo extends React.Component {
state = {count: 0};
render() {
const {count} = this.state;
return <button onClick={() => this.setState({count: count+1})}>count</button>
}
shouldComponentUpdate(){
return false;
}
}
- Environment
[email protected]
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
