diff --git a/README.md b/README.md index 0793532..0df7560 100644 --- a/README.md +++ b/README.md @@ -283,8 +283,21 @@ class Hello extends React.Component { this.state = { currentEnthusiasm: props.enthusiasmLevel || 1 }; } - onIncrement = () => this.updateEnthusiasm(this.state.currentEnthusiasm + 1); - onDecrement = () => this.updateEnthusiasm(this.state.currentEnthusiasm - 1); + onIncrement = () => { + this.setState(nextState => { + return { + currentEnthusiasm: nextState.currentEnthusiasm + 1 + }; + }); + } + + onDecrement = () => { + this.setState(nextState => { + return { + currentEnthusiasm: nextState.currentEnthusiasm - 1 + }; + }); + } render() { const { name } = this.props; @@ -303,10 +316,6 @@ class Hello extends React.Component { ); } - - updateEnthusiasm(currentEnthusiasm: number) { - this.setState({ currentEnthusiasm }); - } } export default Hello;