- 使用 16 版本后的 createRef()函数
-
class MyComponent extends React.Component<iProps, iState> {
-
constructor(props) {
-
super(props);
-
this.inputRef = React.createRef();
-
}
-
render() {
-
return <input type="text" ref={this.inputRef} />;
-
}
-
componentDidMount() {
-
this.inputRef.current.focus();
-
}
-
}
浙公网安备 33010602011771号