Uncaught TypeError: React.createClass is not a function

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



Uncaught TypeError: React.createClass is not a function



To make a react component, i used the following code


var React = require('react');

var RandomWords = React.createClass(
render: function()
return (
<div >
<h4>Random words come here</h4>
</div>
);

);

module.exports =RandomWords;



and then i call this componnet in the root componnet using this:


define(["./RandomWords","react", "react-dom"],
(React, ReactDOM) =>

var Root = React.createClass(
render: function()
return (
<div >
<h1>Welcome to our game</h1>
<RandomWords/>
<UserInput/>
<Statistic/>
</div>
);

);



ReactDOM.render(
React.createElement(Root, null),
document.getElementById('content')
);
);



but it complains that:


Uncaught TypeError: React.createClass is not a function



It seems to me it is because of define(["./RandomWords","react", "react-dom"], but i don't know how can i fix it?


define(["./RandomWords","react", "react-dom"]





npm i react --save-dev ?
– The Reason
Mar 28 '16 at 20:47


npm i react --save-dev





Not getting any sort of error w/ that particular component; are you sure it's installed? jsfiddle.net/ofbosj5g
– markthethomas
Mar 28 '16 at 20:54





yes react is installed and working correctly
– Kamyar Parastesh
Mar 28 '16 at 20:55





Did it help you?
– The Reason
Mar 28 '16 at 21:14





No, but i have update my question, i think the problem is about how i call the Randomwords
– Kamyar Parastesh
Mar 28 '16 at 21:15




1 Answer
1



Is this RequireJS? You specify three dependencies, but only use two. That will fail unless the one you don't use is the last one in the dependency array because the ones you pass to the function will mismatch. The order has to be consistent.



The way is is now, the React variable that is passed into the function is RandomWords, ReactDOM is React and ReactDOM is never injected.


React


RandomWords


ReactDOM


React


ReactDOM



Try


define(["./RandomWords","react", "react-dom"],
(RandomWords, React, ReactDOM) => {






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Firebase Auth - with Email and Password - Check user already registered

Dynamically update html content plain JS

How to determine optimal route across keyboard