Home > Article > Web Front-end > Use react.js to get real DOM nodes
The following editor will bring you an article about getting real DOM nodes in react.js. The editor thinks it’s pretty good, so I’ll share it with you now and give it as a reference. Let’s follow the editor to take a look.
In order to obtain the real DOM node, the text input box must have a ref attribute, and then this.refs.[refName] will return the real DOM node.
var MyComponent = React.createClass({ handleClick: function() { this.refs.myTextInput.focus(); }, render: function() { return ( <p> <input type="text" ref="myTextInput" /> <input type="button" value="Focus the text input" onClick={this.handleClick} /> </p> ); } }); ReactDOM.render( <MyComponent />, document.getElementById('example') );
The above is the detailed content of Use react.js to get real DOM nodes. For more information, please follow other related articles on the PHP Chinese website!