字符串和函数的 React Ref 属性之间的区别

cad*_*zah 5 javascript reactjs

我是 React Web 开发的新手,我正在研究 Component ref。我发现了这个注释:

您可以将函数分配为 JSX的ref属性。此函数仅在安装元素时运行一次。在此函数中,您可以将 DOM 节点放入实例的属性中。

<input ref={(input) => {this.emailInput = input}}
  className="form-control"
  type="text"
  placeholder="cad.co" />
Run Code Online (Sandbox Code Playgroud)

在目前的官方文档中,推荐使用函数作为 ref,并且提到字符串 ref 在未来的版本中可能会被弃用(https://reactjs.org/docs/refs-and-the-dom.html#legacy -api-string-refs)。

我大致了解refsref用作引用变量,并且可以使用ref属性字符串文字

但我不明白如何将 ref 属性与函数参数一起使用。它如何与将字符串属性用于 ref 的工作相同或相似?