mirror of
https://github.com/microsoft/frontend-bootcamp.git
synced 2026-01-26 14:56:42 +08:00
change setState to use a function
Also added note to readme
This commit is contained in:
@@ -14,12 +14,12 @@ export class Counter extends React.Component<any, any> {
|
||||
return (
|
||||
<div>
|
||||
{text}: {counter}
|
||||
<Button onClick={this._onButtonCLick}>Click</Button>
|
||||
<Button onClick={this._onButtonClick}>Click</Button>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
_onButtonCLick = () => {
|
||||
this.setState({ counter: this.state.counter + 1 });
|
||||
_onButtonClick = () => {
|
||||
this.setState((state) => ({ counter: state.counter + 1 }));
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user