我是React.js的新手,刚才我正在学习refReact 的概念.他们在V16.3中有新的createRef API.我试图从REACT DOC这样学习这个 -
import React from "react";
export class MyComponent extends React.Component {
constructor(props) {
super(props);
// create a ref to store the textInput DOM element
this.textInput = React.createRef();
this.focusTextInput = this.focusTextInput.bind(this);
}
focusTextInput() {
// Explicitly focus the text input using the raw DOM API
// Note: we're accessing "current" to get the DOM node
this.textInput.current.focus();
}
render() {
// tell React that we want to associate the <input> ref
// …Run Code Online (Sandbox Code Playgroud)