最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - this.getDomNode() in reapp returns undefined - Stack Overflow

programmeradmin7浏览0评论

I just got started with reapp. I simply created an app. Once the app was created, I modified the default home.jsx as shown:

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,
        };
    }

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

}

export default Reapp(Home);

Now the issue is the this.getDomNode which returns the error

Uncaught TypeError: undefined is not a function

Does anyone have any idea what might be wrong ??

I just got started with reapp. I simply created an app. Once the app was created, I modified the default home.jsx as shown:

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,
        };
    }

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

}

export default Reapp(Home);

Now the issue is the this.getDomNode which returns the error

Uncaught TypeError: undefined is not a function

Does anyone have any idea what might be wrong ??

Share Improve this question edited Apr 21, 2015 at 22:15 tbodt 17k7 gold badges61 silver badges86 bronze badges asked Apr 21, 2015 at 12:19 iJadeiJade 23.9k58 gold badges160 silver badges250 bronze badges 0
Add a ment  | 

3 Answers 3

Reset to default 7

You should use React.findDOMNode(this) instead of this.getDOMNode(), which is deprecated in 0.13.0 and isn't available on classes that extend React.Component.

You should use React.findDOMNode(this) instead of getDomNode,

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

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

Those who are looking for the updated answer for the latest React, here it goes.

React findDOMNode API is been moved into a react-dom package. You can find the reference here.

So use,

import ReactDOM from "react-dom";

ReactDOM.findDOMNode(ponent)

to get the element.

Thank you.

发布评论

评论列表(0)

  1. 暂无评论