Created
February 26, 2021 11:16
-
-
Save KevinVR/7075d3b59ed6d34a15b7f6a342c10e38 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
import React from 'react'; | |
const ClickCounter = ({initialClicks}) => { | |
// If initialClicks is not defined, use 0 as default | |
const [clicks, setClicks] = useState(initialClicks || 0); | |
// Implement an onClick method for the button | |
const incrementClicks = () => { | |
setClicks(clicks + 1); | |
}; | |
// Use React.Fragment to avoid extra divs | |
return <> | |
<h1>Click Counter</h1> | |
<p>Amount of clicks: {clicks}</p> | |
<button onClick={incrementClicks}>Click me!</button> | |
</>; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment