Created
December 25, 2018 12:33
-
-
Save nirsky/1253db73812b224cf4b3944a03d58bd5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Class | |
class CounterButton extends Component { | |
constructor() { | |
super(); | |
this.state = { | |
count: 0 | |
} | |
} | |
render() { | |
return <button onClick={() => this.setState({ count: this.state.count + 1 })}> | |
{ this.state.count } | |
</button> | |
} | |
} | |
//Hooks | |
const CounterButton = props => { | |
const [count, setCount] = useState(0); | |
return <button onClick={() => setCount(count + 1)}> | |
{ count } | |
</button> | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment