Created
May 9, 2020 04:22
-
-
Save elit-altum/29e5e85f1026d42a916f8888ff36923b to your computer and use it in GitHub Desktop.
A React counter app
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
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