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回购的相关代码和承诺:
> @L_403_3@
> https://github.com/facebook/react/commit/b46a6ce4bb8d6087ed424764f41fe4b8e248b3b4
> https://github.com/facebook/react/commit/fb23276178b28fdcb75aa22be013a91755f7ad0a