Skip to content

Instantly share code, notes, and snippets.

@zulnabil
Last active June 28, 2019 12:39
Show Gist options
  • Select an option

  • Save zulnabil/b25f91295e7177f9b094a7f50458d82f to your computer and use it in GitHub Desktop.

Select an option

Save zulnabil/b25f91295e7177f9b094a7f50458d82f to your computer and use it in GitHub Desktop.
Component Foul
import React from 'react'
import styled from 'styled-components'
const ObjFoul = styled.div`
text-align: center;
`
const PointFoul = styled.div`
font-size: 24pt;
`
function Foul(props) {
const [point, setPoint] = React.useState(props.point)
const handleIncrement = () => {
setPoint(point+1)
}
const handleDecrement = () => {
if (point > 0) {
setPoint(point-1)
}
}
return (
<ObjFoul>
<PointFoul>
{point}
</PointFoul>
<div>
<button onClick={handleIncrement}>+</button>
<button onClick={handleDecrement}>-</button>
</div>
</ObjFoul>
)
}
export default Foul
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment