Last active
June 28, 2019 12:40
-
-
Save zulnabil/63eb6961dfddab63d420b5381df57b1a to your computer and use it in GitHub Desktop.
Component Score
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 ObjScore = styled.div` | |
| text-align: center; | |
| ` | |
| const NameTeam = styled.div` | |
| font-size: 18pt; | |
| ` | |
| const PointScore = styled.div` | |
| font-size: 42pt; | |
| font-weight: 600; | |
| ` | |
| function Score(props) { | |
| const [team, setTeam] = React.useState(props.team) | |
| const [point, setPoint] = React.useState(0) | |
| const handleIncrement = () => { | |
| setPoint(point+1) | |
| } | |
| const handleDecrement = () => { | |
| if (point > 0) { | |
| setPoint(point-1) | |
| } | |
| } | |
| return ( | |
| <ObjScore> | |
| <NameTeam> | |
| {team} | |
| </NameTeam> | |
| <PointScore> | |
| {point} | |
| </PointScore> | |
| <div> | |
| <button onClick={handleIncrement}>+</button> | |
| <button onClick={handleDecrement}>-</button> | |
| </div> | |
| </ObjScore> | |
| ) | |
| } | |
| export default Score |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment