Skip to content

Instantly share code, notes, and snippets.

@elit-altum
Created May 9, 2020 04:22
Show Gist options
  • Save elit-altum/29e5e85f1026d42a916f8888ff36923b to your computer and use it in GitHub Desktop.
Save elit-altum/29e5e85f1026d42a916f8888ff36923b to your computer and use it in GitHub Desktop.
A React counter app
import React, { useState } from 'react';
const Counter = () => {
const [count, setCount] = useState(0);
const handleIncrement = () => {
const prevCount = count;
setCount(prevCount + 1);
}
const handleDecrement = () => {
const prevCount = count;
setCount(prevCount - 1);
}
return (
<div>
<h2>{count}</h2>
<button onClick={handleIncrement}>Add One</button>
<button onClick={handleDecrement}>Subtract One</button>
</div>
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment