mirror of
https://github.com/reactjs/react.dev.git
synced 2026-02-24 04:33:10 +00:00
Updated docs examples/recommendations to use findDOMNode instead of getDOMNode
This commit is contained in:
@@ -487,14 +487,15 @@ Let's make the form interactive. When the user submits the form, we should clear
|
||||
var CommentForm = React.createClass({
|
||||
handleSubmit: function(e) {
|
||||
e.preventDefault();
|
||||
var author = this.refs.author.getDOMNode().value.trim();
|
||||
var text = this.refs.text.getDOMNode().value.trim();
|
||||
var author = React.findDOMNode(this.refs.author).value.trim();
|
||||
var text = React.findDOMNode(this.refs.text).value.trim();
|
||||
if (!text || !author) {
|
||||
return;
|
||||
}
|
||||
// TODO: send request to the server
|
||||
this.refs.author.getDOMNode().value = '';
|
||||
this.refs.text.getDOMNode().value = '';
|
||||
React.findDOMNode(this.refs.author).value = '';
|
||||
React.findDOMNode(this.refs.text).value = '';
|
||||
return;
|
||||
},
|
||||
render: function() {
|
||||
return (
|
||||
@@ -516,7 +517,7 @@ Call `preventDefault()` on the event to prevent the browser's default action of
|
||||
|
||||
##### Refs
|
||||
|
||||
We use the `ref` attribute to assign a name to a child component and `this.refs` to reference the component. We can call `getDOMNode()` on a component to get the native browser DOM element.
|
||||
We use the `ref` attribute to assign a name to a child component and `this.refs` to reference the component. We can call `React.findDOMNode(component)` on a component to get the native browser DOM element.
|
||||
|
||||
##### Callbacks as props
|
||||
|
||||
@@ -568,14 +569,15 @@ Let's call the callback from the `CommentForm` when the user submits the form:
|
||||
var CommentForm = React.createClass({
|
||||
handleSubmit: function(e) {
|
||||
e.preventDefault();
|
||||
var author = this.refs.author.getDOMNode().value.trim();
|
||||
var text = this.refs.text.getDOMNode().value.trim();
|
||||
var author = React.findDOMNode(this.refs.author).value.trim();
|
||||
var text = React.findDOMNode(this.refs.text).value.trim();
|
||||
if (!text || !author) {
|
||||
return;
|
||||
}
|
||||
this.props.onCommentSubmit({author: author, text: text});
|
||||
this.refs.author.getDOMNode().value = '';
|
||||
this.refs.text.getDOMNode().value = '';
|
||||
React.findDOMNode(this.refs.author).value = '';
|
||||
React.findDOMNode(this.refs.text).value = '';
|
||||
return;
|
||||
},
|
||||
render: function() {
|
||||
return (
|
||||
|
||||
Reference in New Issue
Block a user