Skip to content

Instantly share code, notes, and snippets.

@iamsaief
Created August 22, 2020 15:09
Show Gist options
  • Save iamsaief/28a43c4273da36f7ca184af19f7fd2c4 to your computer and use it in GitHub Desktop.
Save iamsaief/28a43c4273da36f7ca184af19f7fd2c4 to your computer and use it in GitHub Desktop.
import React, { useState } from "react";
function App() {
return (
<div>
<Counter />
</div>
);
}
function Counter() {
// Declare a new state variable, which we'll call "count"
const [count, setCount] = useState(0);
const handleIncrease = () => setCount(count + 1);
const handleDecrease = () => setCount(count - 1);
return (
<div>
<h1>
Counter:
<button onClick={handleDecrease}>-</button>
<strong> {count} </strong>
<button onClick={handleIncrease}>+</button>
</h1>
</div>
);
}
export default App;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment