React.findDOMNode(this.refs.email).value
和
this.refs.email.getDOMNode().value
他们正在做同样的事情 – 获取元素的价值,但我应该在哪里使用哪一个。
Added new top-level API
React.findDOMNode(component)
,which should be
used in place ofcomponent.getDOMNode()
. The base class for ES6-based
components will not havegetDOMNode
. 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中被删除(但不要引用我,因为我找不到一个很好的参考)。
编辑:更新以反映反应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.
另请注意,对于React DOM组件,不再需要调用findDOMNode或getDOMNode,因为0.14:
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回购的相关代码和承诺:
> https://github.com/facebook/react/blob/a6d03f36a4a9e7c1e6688bdba89656f2e20e7df8/src/modern/class/ReactComponent.js#L101-L104
> https://github.com/facebook/react/commit/b46a6ce4bb8d6087ed424764f41fe4b8e248b3b4
> https://github.com/facebook/react/commit/fb23276178b28fdcb75aa22be013a91755f7ad0a
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。