inputRef.current); return
赞
踩
import React, { useRef, useEffect, useImperativeHandle, forwardRef } from "react"; function ChildInputComponent(props, ref) { const inputRef = useRef(null); useImperativeHandle(ref, () => inputRef.current); return <input type="text" name="child input" ref={inputRef} />; } const ChildInput = forwardRef(ChildInputComponent); function App() { const inputRef = useRef(null); useEffect(() => { inputRef.current.focus(); }, []); return ( <div> <ChildInput ref={inputRef} /> </div> ); }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。