<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN" "http://www.wapforum.org/DTD/wml_1.1.xml">
<wml>
<head><meta forua="true" http-equiv="Cache-Control" content="max-age=0" /></head>
<card title="自定义组件ref不支持字符串名称：Function components cannot have string refs in React" id="card1">
<p> 游客</p><p>
标题:自定义组件ref不支持字符串名称：Function components cannot have string refs in React<br/>
正文:<br/>
 The error &amp;quot;Function components cannot have string refs&amp;quot; occurs when we use a string as a ref in a function component.To solve the error use the useRef() hook to get a mutable ref object that you can use as a ref inside of the component. import {useEffect, useRef} from 'react'; export default function App() {  const refContainer = useRef(null);   useEffect(() =&amp;gt; {    // 👇️ This is reference to input element    console.log(refContainer.current);     refContainer.current.focus();  }, []);   return (    &amp;lt;div&amp;gt;      &amp;lt;input type=&amp;quot;text&amp;quot; id=&amp;quot;message&amp;quot; ref={refContainer} /&amp;gt;    &amp;lt;/div&amp;gt;  );} import {useEffect, useRef} from 'react'; export default function App() {  const refContainer = useRef(null);   const refCounter = useRef(0);   useEffect(() =&amp;gt; {    // 👇️ This is refer<br/><a href="http://camnpr.com/wap.asp?mode=WAP&amp;act=View&amp;id=2299&amp;Page=1">[&lt;&lt;]</a><a href="http://camnpr.com/wap.asp?mode=WAP&amp;act=View&amp;id=2299&amp;Page=1">[[1]]</a><a href="http://camnpr.com/wap.asp?mode=WAP&amp;act=View&amp;id=2299&amp;Page=2">[2]</a><a href="http://camnpr.com/wap.asp?mode=WAP&amp;act=View&amp;id=2299&amp;Page=2">[&gt;&gt;]</a><br/>
<br/>
<a href="wap.asp?act=Com&amp;id=2299">查看评论(0)</a><br/>
<a href="wap.asp?act=AddCom&amp;inpId=2299">发表评论</a><br/><br/>

<br/>

<br/>
<a href="http://camnpr.com/wap.asp">首页</a>
</p>
</card>
</wml>