Last active
          March 17, 2023 13:27 
        
      - 
      
 - 
        
Save LucasCalazans/7951d5ab1f308162c627a2f2d7adc3ba to your computer and use it in GitHub Desktop.  
    Comparation with React Hooks
  
        
  
    
      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
    
  
  
    
  | // Usando classe | |
| class Counter extends Component { | |
| state = { | |
| counter: 1, | |
| } | |
| incrementCounter = () => { | |
| this.setState(({ counter }) => ({ counter: counter + 1 })); | |
| }; | |
| render() { | |
| return ( | |
| <button onClick={this.incrementCounter}>{this.state.counter}</button> | |
| ) | |
| } | |
| } | |
| // Mesma funcionalidade usando Hooks | |
| const Counter = () => { | |
| const [counter, setCounter] = useState(1) | |
| return ( | |
| <button onClick={() => setCounter(counter + 1)}>{counter}</button> | |
| ); | |
| } | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment