Skip to content

Instantly share code, notes, and snippets.

@r3dm1ke
Created June 10, 2020 15:39
Show Gist options
  • Save r3dm1ke/7f3cfdcba209d0a711858ae7eba0cc2f to your computer and use it in GitHub Desktop.
Save r3dm1ke/7f3cfdcba209d0a711858ae7eba0cc2f to your computer and use it in GitHub Desktop.
import React, {Component, useState} from 'react';
// Class
class App extends Component {
constructor(props) {
super(props);
this.state = {counter: 0};
}
render() {
return (
<button onClick={() => this.setState({counter: this.state.counter + 1})}>
{counter}
</button>
);
}
}
// Functional
const App = () => {
const [counter, setCounter] = useState(0);
return (
<button onClick={() => setCounter(counter + 1)}>{counter}</button>
);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment