IlanZiin

#033 UTILIZAÇÃO MAIS COMUM DO USEREF

Sep 14th, 2022
1,562
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 inputRef = useRef()
  7.  
  8.     function executar(){
  9.         inputRef.current.focus()
  10.     }
  11.  
  12.     return (
  13.         <>
  14.             <h1>React Hooks - useRef</h1>
  15.             <hr/>
  16.             <input ref={inputRef} type="text" value={texto} onChange={evento => setTexto(evento.target.value) } />
  17.             <hr/>
  18.             <button onClick={executar}>Clicar</button>
  19.         </>
  20.     )
  21. }
Advertisement
Add Comment
Please, Sign In to add comment