小编Ale*_*x C的帖子

反应参考电流为 NULL

我的代码取自官方 React Ref 文档

import React from "react";
import { render } from "react-dom";

class CustomTextInput 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();
    console.log(this.textInput);
  }

  render() {
    // tell React that we want to associate the <input> ref
    // …
Run Code Online (Sandbox Code Playgroud)

ref reactjs

7
推荐指数
1
解决办法
6455
查看次数

标签 统计

reactjs ×1

ref ×1