Skip to content

Instantly share code, notes, and snippets.

@gillesdemey
Created November 18, 2018 14:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gillesdemey/a6f982e6a9e587c68ad00f7af33a3f53 to your computer and use it in GitHub Desktop.
Save gillesdemey/a6f982e6a9e587c68ad00f7af33a3f53 to your computer and use it in GitHub Desktop.
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