iJade
iJade

Reputation: 23801

this.getDomNode() in reapp returns undefined

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

  componentDidMount() {
    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 ??

Upvotes: 1

Views: 2458

Answers (3)

Balasubramani M
Balasubramani M

Reputation: 8358

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(component)

to get the element.

Thank you.

Upvotes: 1

Oleksandr T.
Oleksandr T.

Reputation: 77482

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

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

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

Upvotes: 2

Alexandre Kirszenberg
Alexandre Kirszenberg

Reputation: 36418

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.

Upvotes: 7

Related Questions