this.getDomNode() 重新应用 returns 未定义

this.getDomNode() in reapp returns undefined

我刚开始使用 reapp。我只是创建了一个应用程序。创建应用程序后,我修改了默认值 home.jsx,如下所示:

import { Reapp, React } from 'reapp-kit';

class Home extends React.Component {

  render() {
    return (
      <div className='map'></div>
    );
  }

  getDefaultProps() {
        return {
            initialZoom: 8,
            mapCenterLat: 43.6425569,
            mapCenterLng: -79.4073126,
        };
    }

  componentDidMount() {
    console.log('Dom node is ',this.getDomNode());
  }

}

export default Reapp(Home);

现在的问题是 this.getDomNode 其中 returns 错误

Uncaught TypeError: undefined is not a function

有人知道哪里出了问题吗??

您应该使用 React.findDOMNode(this) 而不是 this.getDOMNode()which is deprecated in 0.13.0,并且在扩展 React.Component.

的 类 上不可用

您应该使用 React.findDOMNode(this) 而不是 getDomNode,

class Home extends React.Component {
  render() {
    return (
      <div className='map'></div>
    );
  }

  componentDidMount() {
    console.log('Dom node is ', React.findDOMNode(this));
  }
}

那些正在寻找最新 React 的更新答案的人,就在这里。

React findDOMNode API 已移至 react-dom 包中。您可以找到参考 here.

所以用,

import ReactDOM from "react-dom";

ReactDOM.findDOMNode(component)

获取元素。

谢谢。