Browse Source

Move constructor out of render

main
Sean Snyder 7 years ago
parent
commit
e1689b0f20
  1. 17
      content/docs/accessibility.md

17
content/docs/accessibility.md

@ -147,21 +147,22 @@ To set focus in React, we can use [Refs to DOM elements](/docs/refs-and-the-dom.
Using this, we first create a ref to an element in the JSX of a component class: Using this, we first create a ref to an element in the JSX of a component class:
```javascript{4-5,8-9,13} ```javascript{4-5,8-9,13}
render() { class CustomTextInput extends React.Component {
constructor(props) { constructor(props) {
super(props); super(props);
// Create a ref to store the textInput DOM element // Create a ref to store the textInput DOM element
this.textInput = React.createRef(); this.textInput = React.createRef();
} }
// ... render() {
// Use the `ref` callback to store a reference to the text input DOM // Use the `ref` callback to store a reference to the text input DOM
// element in an instance field (for example, this.textInput). // element in an instance field (for example, this.textInput).
return ( return (
<input <input
type="text" type="text"
ref={this.textInput} ref={this.textInput}
/> />
); );
}
} }
``` ```

Loading…
Cancel
Save