Skip to content

Commit 0d9b921

Browse files
hartzissophiebits
authored andcommitted
More explicit class method for ref doc (facebook#10228)
After realizing this was the second time I've visited this exact page within a year and second guessing myself that the `textInput` ref isn't actually the `<input />` element. I decided to attempt to make this a little more explicit; you are actually accessing the method on the child class and not the `focus` method on the dom input element. Having them named the same caused some confusion. (cherry picked from commit 6d37c05)
1 parent 88453bd commit 0d9b921

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

docs/docs/refs-and-the-dom.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@ When the `ref` attribute is used on an HTML element, the `ref` callback receives
3939
class CustomTextInput extends React.Component {
4040
constructor(props) {
4141
super(props);
42-
this.focus = this.focus.bind(this);
42+
this.focusTextInput = this.focusTextInput.bind(this);
4343
}
4444
45-
focus() {
45+
focusTextInput() {
4646
// Explicitly focus the text input using the raw DOM API
4747
this.textInput.focus();
4848
}
@@ -77,7 +77,7 @@ When the `ref` attribute is used on a custom component declared as a class, the
7777
```javascript{3,9}
7878
class AutoFocusTextInput extends React.Component {
7979
componentDidMount() {
80-
this.textInput.focus();
80+
this.textInput.focusTextInput();
8181
}
8282
8383
render() {

0 commit comments

Comments
 (0)