Created
October 5, 2019 13:12
-
-
Save brooksbecton/510be8805966a21736db89b13cf03ae5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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