Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import React, { useState, useEffect, useRef } from 'react'
- export default function App(){
- const [texto, setTexto] = useState('')
- const inputRef = useRef()
- function executar(){
- inputRef.current.focus()
- }
- return (
- <>
- <h1>React Hooks - useRef</h1>
- <hr/>
- <input ref={inputRef} type="text" value={texto} onChange={evento => setTexto(evento.target.value) } />
- <hr/>
- <button onClick={executar}>Clicar</button>
- </>
- )
- }
Advertisement
Add Comment
Please, Sign In to add comment