Created
November 18, 2018 14:24
-
-
Save gillesdemey/a6f982e6a9e587c68ad00f7af33a3f53 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, { Fragment, useState } from 'react' | |
import Button from '../button/button' | |
function Counter (props) { | |
const [count, setCount] = useState(props.initialCount) | |
function increment () { | |
setCount(count + 1) | |
} | |
function decrement () { | |
setCount(count - 1) | |
} | |
return ( | |
<Fragment> | |
I've counted {count}. | |
<div> | |
<Button onClick={increment}>+</Button> | |
<Button onClick={decrement}>-</Button> | |
</div> | |
</Fragment> | |
) | |
} | |
Counter.defaultProps = { | |
initialCount: 0 | |
} | |
export default Counter |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment