admin管理员组文章数量:1390455
I am a newer JS developer and I am exploring React-Native. I recently purchased "Learning React Native" by Bonnie Eisenman and am working on the very first mini-project - a very basic weather app.
Unfortunately, I can't get the code the author provides to work (see below for some of the code, or see the whole thing here). I keep getting the error "React.createClass is not a function", even though I've seen dozens of other examples where this works just fine. I've been spending hours researching and asking questions with no success. Please help!
var React = require('react-native');
var {
StyleSheet,
Text,
View,
TextInput
} = React;
var WeatherProject = React.createClass({
....
});
module.exports = WeatherProject;
I am a newer JS developer and I am exploring React-Native. I recently purchased "Learning React Native" by Bonnie Eisenman and am working on the very first mini-project - a very basic weather app.
Unfortunately, I can't get the code the author provides to work (see below for some of the code, or see the whole thing here). I keep getting the error "React.createClass is not a function", even though I've seen dozens of other examples where this works just fine. I've been spending hours researching and asking questions with no success. Please help!
var React = require('react-native');
var {
StyleSheet,
Text,
View,
TextInput
} = React;
var WeatherProject = React.createClass({
....
});
module.exports = WeatherProject;
Share
Improve this question
asked Jun 15, 2016 at 23:32
Ricky PadillaRicky Padilla
2565 silver badges7 bronze badges
1 Answer
Reset to default 5according to the react-native docs https://facebook.github.io/react-native/
You should require React from 'react' not 'react-native'
And require your StyleSheet, Text, View, TextInput from 'react-native' (like you're currently doing)
from the docs:
import React, {
Component,
} from 'react';
import {
TabBarIOS,
NavigatorIOS,
} from 'react-native';
class App extends Component {
render() {
return (
<TabBarIOS>
<TabBarIOS.Item title="React Native" selected={true}>
<NavigatorIOS initialRoute={{ title: 'React Native' }} />
</TabBarIOS.Item>
</TabBarIOS>
);
}
}
This is using ES6 / ES2015 syntax of extending the react Component. Yours will look more like this:
var React = require('react');
var {
StyleSheet,
Text,
View,
TextInput
} = require('react-native');
var WeatherProject = React.createClass({
....
});
module.exports = WeatherProject;
Although based on the object destructuring you're doing you are already in an environment that supports ES6 and it may be better to just use ES6 instead.
本文标签: javascriptGetting error quotreactcreateclass is not a functionquotStack Overflow
版权声明:本文标题:javascript - Getting error: "react.createclass is not a function" - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744623384a2616165.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论