ReactJS findDOMNode and getDOMNode are not functions

ReactjsReact Dom

Reactjs Problem Overview


I'm building a web-app with ReactJS and Flux and I'm trying to get the node of my current div using the method findDOMNode and I get the next error:

Uncaught TypeError: React.findDOMNode is not a function

So, I tried to use getDOMNode and I get the very same error:

Uncaught TypeError: React.getDOMNode is not a function

I'm using npm to build the JS, the code where I use these methods:

var React = require('react');
var stores = require('../stores');
var MessagesUserContainer = require('./messageusercontainer');
var ChatStore = stores.ChatStore;
var owner = stores.getOwner();

var MessagesList = React.createClass({

	getInitialState: function(){
		return {'muc': []};
	},
	componentDidUpdate: function(){
		var node = React.findDOMNode(this); //Error here
  		node.scrollTop = node.scrollHeight;
	},
	render: function(){
		return (
				<div className="chatScroll">
					{this.state.muc}
				</div>
			)
	}
});

module.exports = MessagesList;

ReactJS verion: 0.14.0

EDIT

As pointed out in the answers, the DOM library as of v0.14.0 is out of the React core, so I made a few changes to my code:

var React = require('react');
var ReactDOM = require('react-dom');
var stores = require('../stores');
var MessagesUserContainer = require('./messageusercontainer');
var ChatStore = stores.ChatStore;
var owner = stores.getOwner();

var MessagesList = React.createClass({

	getInitialState: function(){
		return {'muc': []};
	},
	componentDidUpdate: function(){
		var node = ReactDOM.findDOMNode(this);
  		node.scrollTop = node.scrollHeight;
	},
	render: function(){
		return (
				<div className="chatScroll">
					{this.state.muc}
				</div>
			)
	}
});

module.exports = MessagesList;

But I got another problem:

Uncaught Error: Invariant Violation: findDOMNode was called on an unmounted component.

Reactjs Solutions


Solution 1 - Reactjs

Changed in latest React:

ReactDOM.findDOMNode

https://facebook.github.io/react/docs/top-level-api.html#reactdom.finddomnode

It is in the react-dom package. Note that ReactDOMServer has also been moved into another package. Probably in preparation for React related platform-specific APIs (such as React native).

To import/ require the package:

import ReactDOM from "react-dom";

or

 var ReactDOM = require('react-dom').

Solution 2 - Reactjs

In react v0.14 DOM library has been moved from React.js itself. There are some BC changes, but if you wrote your code in a proper way then changes won't be painful. Please read here for full overview: https://facebook.github.io/react/blog/#major-changes

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionVictor Castillo TorresView Question on Stackoverflow
Solution 1 - Reactjsuser120242View Answer on Stackoverflow
Solution 2 - ReactjsPawelView Answer on Stackoverflow