0
点赞
收藏
分享

微信扫一扫

React 组件的三大核心属性之 ref 在函数式组件中的基本使用

sullay 2022-02-07 阅读 44

使用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>
    )

}
举报

相关推荐

0 条评论