Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import React, { useState, useEffect } from 'react'
- export default function App(){
- const [valor, setValor] = useState(() => {
- return 10
- })
- const [valor2, setValor2] = useState(() => {
- return 100
- })
- function alterar(){
- setValor(valor + 1)
- }
- function alterar2(){
- setValor2(valor2 + 1)
- }
- useEffect(() => {
- console.log('alterado')
- }, [valor])
- return (
- <>
- <h1>React Hooks - useEffect</h1>
- <h3>Valor: {valor}</h3>
- <h3>Valor2: {valor2}</h3>
- <button onClick={alterar}>Alterar</button>
- <button onClick={alterar2}>Alterar</button>
- </>
- )
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement