Created
          April 30, 2020 22:59 
        
      - 
      
- 
        Save miguelzinhe/2315d58134f67b852fa235c9219f1cb0 to your computer and use it in GitHub Desktop. 
    Challenge C*d*l*ty Like
  
        
  
    
      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 classNames from 'classnames' | |
| import { Component } from 'react' | |
| export default class LikeButton extends Component { | |
| constructor(props) { | |
| super(props); | |
| this.state = { liked: false, count: 100 }; | |
| } | |
| onClickAddLikeHandler = () => { | |
| this.setState({ count: this.state.count + 1, liked: true }); | |
| }; | |
| onClickRemoveLikeHandler = () => { | |
| this.setState({ count: this.state.count - 1, liked: false }); | |
| }; | |
| render() { | |
| const { liked, count } = this.state; | |
| return ( | |
| <> | |
| <div> | |
| <button | |
| className={classNames("like-button", { liked })} | |
| onClick={ | |
| liked ? this.onClickRemoveLikeHandler : this.onClickAddLikeHandler | |
| } | |
| > | |
| Like | <span className="likes-counter">{count}</span> | |
| </button> | |
| </div> | |
| <style>{` | |
| .like-button { | |
| font-size: 1rem; | |
| padding: 5px 10px; | |
| color: #585858; | |
| } | |
| .liked { | |
| font-weight: bold; | |
| color: #1565c0; | |
| } | |
| `}</style> | |
| </> | |
| ); | |
| } | |
| } | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment