Skip to content

Instantly share code, notes, and snippets.

@brooksbecton
Created October 5, 2019 13:12
Show Gist options
  • Save brooksbecton/510be8805966a21736db89b13cf03ae5 to your computer and use it in GitHub Desktop.
Save brooksbecton/510be8805966a21736db89b13cf03ae5 to your computer and use it in GitHub Desktop.
const App: React.FC = () => {
const defaultCountValue = 0;
const [count, setCount] = useState(defaultCountValue);
const handleIncrement = (currentCount: number) => {
setCount(currentCount + 1);
};
const handleDecrement = (currentCount: number) => {
setCount(currentCount - 1);
};
const handleReset = () => {
setCount(defaultCountValue);
};
return (
<div
style={{
display: "flex",
justifyContent: "center",
height: "50%",
paddingTop: "20%",
}}
>
<label>
Count:
<input value={count} type="number" />
</label>
<button onClick={() => handleIncrement(count)}>+</button>
<button onClick={() => handleDecrement(count)}>-</button>
<button onClick={handleReset}>Reset</button>
</div>
);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment