Last active
June 28, 2019 12:39
-
-
Save zulnabil/b25f91295e7177f9b094a7f50458d82f to your computer and use it in GitHub Desktop.
Component Foul
This file contains hidden or 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' | |
| 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