引用不断返回null

时间:2019-05-25 20:01:28

标签: reactjs dom ref

我看了很多参考示例,但没有一个在工作。有人可以告诉我为什么这个ref总是返回null吗?

class GeneralNav extends Component {
  constructor(props) {
    super(props);
    this.showMenuTitle = React.createRef();
    console.log(this.showMenuTitle.current)
  }

  render() {
    return (
        <div>
          <p ref={this.showMenuTitle}>menu</p>
        </div>
    );
  }
}


0 个答案:

没有答案
相关问题