IlanZiin

#032 INTRODUÇÃO AO USEREF

Sep 14th, 2022
1,072
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import React, { useState, useEffect, useRef } from 'react'
  2.  
  3. export default function App(){
  4.  
  5.     const [texto, setTexto] = useState('')
  6.     const total = useRef(1)
  7.  
  8.     useEffect(() => {
  9.         total.current++;
  10.     })
  11.  
  12.     return (
  13.         <>
  14.             <h1>React Hooks - useRef</h1>
  15.             <hr/>
  16.             <input type="text" value={texto} onChange={evento => setTexto(evento.target.value) } />
  17.             <hr/>
  18.             <p>O texto é: <strong>{texto}</strong></p>
  19.             <hr/>
  20.             <p>Total: {total.current}</p>
  21.         </>
  22.     )
  23. }
Advertisement
Add Comment
Please, Sign In to add comment