Skip to content

Instantly share code, notes, and snippets.

@yash-278
Created July 25, 2022 10:54
Show Gist options
  • Save yash-278/ae3730edbc57e34ba759a4d1c590cec3 to your computer and use it in GitHub Desktop.
Save yash-278/ae3730edbc57e34ba759a4d1c590cec3 to your computer and use it in GitHub Desktop.
React counter
import "./styles.css";
import { useState } from "react";
export default function App() {
const [count, setCount] = useState(0);
let incrementCount = () => {
setCount(count + 1);
};
let decrementCount = () => {
setCount(count - 1);
};
return (
<div className="App">
<div>
<div class="count">
<h3>Count:</h3>
<h1>{count}</h1>
</div>
<div class="buttons">
<button onClick={decrementCount}>Decrement</button>
<button onClick={incrementCount}>Increment</button>
</div>
</div>
</div>
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment