1.使用useRef(),在标签上绑定对应的ref={}
2.使用useRef().current获取dom
import { useRef } from 'react'
function App() {
const inputRef = useRef(null)
const handleClickButton = ()=>{
console.log(inputRef.current);
}
return (
<>
<div><input type="text" ref={inputRef} /></div>
<button onClick={handleClickButton}>获取dom</button>
</>
)
}
export default App