Advertisement
IlanZiin

#029 INTRODUÇÃO AO USEEFFECT

Sep 13th, 2022
1,276
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import React, { useState, useEffect } from 'react'
  2.  
  3. export default function App(){
  4.  
  5.     const [valor, setValor] = useState(() => {
  6.         return 10
  7.     })
  8.  
  9.     const [valor2, setValor2] = useState(() => {
  10.         return 100
  11.     })
  12.  
  13.     function alterar(){
  14.         setValor(valor + 1)
  15.     }
  16.  
  17.     function alterar2(){
  18.         setValor2(valor2 + 1)
  19.     }
  20.  
  21.     useEffect(() => {
  22.         console.log('alterado')
  23.     }, [valor])
  24.  
  25.     return (
  26.         <>
  27.             <h1>React Hooks - useEffect</h1>
  28.             <h3>Valor: {valor}</h3>
  29.             <h3>Valor2: {valor2}</h3>
  30.             <button onClick={alterar}>Alterar</button>
  31.             <button onClick={alterar2}>Alterar</button>
  32.         </>
  33.     )
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement