gpt4 book ai didi

reactjs - React.js : The difference between findDOMNode and getDOMNode

转载 作者:行者123 更新时间:2023-12-03 13:00:40 26 4
gpt4 key购买 nike

谁能告诉我两者有什么区别

React.findDOMNode(this.refs.email).value

this.refs.email.getDOMNode().value

他们在做同样的事情 - 获取元素的值,但是我应该在哪里使用哪个。

最佳答案

component.getDOMNode() 从 React 0.13 开始已弃用:

Added new top-level API React.findDOMNode(component), which should be used in place of component.getDOMNode(). The base class for ES6-based components will not have getDOMNode. This change will enable some more patterns moving forward.

通过 http://facebook.github.io/react/blog/2015/03/10/react-v0.13.html#new-features

它可能会在 React 的 future 版本中被删除(但不要引用我的话,因为我找不到好的引用资料)。

<小时/>

编辑:更新以反射(reflect) React 0.14

getDOMNode() 在 0.13 和 0.14 中抛出警告,它将在 0.15 中完全删除:

With each returned DOM node, we've added a getDOMNode method for backwards compatibility that will work with a warning until 0.15.

通过 https://facebook.github.io/react/blog/2015/10/07/react-v0.14.html#new-deprecations-introduced-with-a-warning

另请注意,从 0.14 开始,React DOM 组件不再需要调用 findDOMNodegetDOMNode:

The other big change we’re making in this release is exposing refs to DOM components as the DOM node itself. That means: we looked at what you can do with a ref to a React DOM component and realized that the only useful thing you can do with it is call this.refs.giraffe.getDOMNode() to get the underlying DOM node. Starting with this release, this.refs.giraffe is the actual DOM node. Note that refs to custom (user-defined) components work exactly as before; only the built-in DOM components are affected by this change.

通过 https://facebook.github.io/react/blog/2015/10/07/react-v0.14.html#dom-node-refs

<小时/>

来自 GitHub 上 React 存储库的相关代码和提交:

关于reactjs - React.js : The difference between findDOMNode and getDOMNode,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30190608/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com