Skip to content

Commit

Permalink
fix demo07
Browse files Browse the repository at this point in the history
  • Loading branch information
ruanyf committed Nov 7, 2015
1 parent 7f66384 commit cb7cb65
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -217,12 +217,12 @@ ReactDOM.render(

## Demo07: Finding a DOM node ([source](https://github.com/ruanyf/react-demos/blob/master/demo07/index.html))

Sometimes you need to reference a DOM node in a component. React gives you `ReactDOM.findDOMNode()` to find it.
Sometimes you need to reference a DOM node in a component. React gives you the `ref` attribute to find it.

```js
var MyComponent = React.createClass({
handleClick: function() {
ReactDOM.findDOMNode(this.refs.myTextInput).focus();
this.refs.myTextInput.focus();
},
render: function() {
return (
Expand All @@ -240,7 +240,7 @@ ReactDOM.render(
);
```

The desired DOM node should have a `ref` attribute, and `ReactDOM.findDOMNode(this.refs.[refName])` would return the corresponding DOM node. Please be minded that you could do that only after this component has been mounted into the DOM, otherwise you get `null`.
The desired DOM node should have a `ref` attribute, and `this.refs.[refName]` would return the corresponding DOM node. Please be minded that you could do that only after this component has been mounted into the DOM, otherwise you get `null`.

## Demo08: this.state ([source](https://github.com/ruanyf/react-demos/blob/master/demo08/index.html))

Expand Down
2 changes: 1 addition & 1 deletion demo07/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<script type="text/babel">
var MyComponent = React.createClass({
handleClick: function() {
ReactDOM.findDOMNode(this.refs.myTextInput).focus();
this.refs.myTextInput.focus();
},
render: function() {
return (
Expand Down

0 comments on commit cb7cb65

Please sign in to comment.