使用Hook可以在函数式组件中使用ref
import React, {useRef} from 'react'
import {Button} from "antd";
export default function FuncCompDemo(props) {
//创建ref
const refText = useRef()
function showText() {
alert(refText.current.value)
}
return (
<div>
<input type="text" ref = {refText}/>
<button onClick={showText}>展示文本内容</button>
</div>
)
}