Skip to content

Commit

Permalink
Merge pull request #216 from knpwrs/ref-did-mount
Browse files Browse the repository at this point in the history
Explicitly note that ref callbacks are called before componentDidMount.
  • Loading branch information
bvaughn authored Oct 30, 2017
2 parents f5ab0b4 + 18097a2 commit d9d6d95
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion content/docs/refs-and-the-dom.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class CustomTextInput extends React.Component {
}
```

React will call the `ref` callback with the DOM element when the component mounts, and call it with `null` when it unmounts.
React will call the `ref` callback with the DOM element when the component mounts, and call it with `null` when it unmounts. `ref` callbacks are invoked before `componentDidMount` or `componentDidUpdate` lifecycle hooks.

Using the `ref` callback just to set a property on the class is a common pattern for accessing DOM elements. The preferred way is to set the property in the `ref` callback like in the above example. There is even a shorter way to write it: `ref={input => this.textInput = input}`.

Expand Down

0 comments on commit d9d6d95

Please sign in to comment.