React.createElement:type不应为null

时间:2016-01-16 07:09:11

标签: ios reactjs react-native createelement

我从here复制了代码。

这会抛出此警告:

warning

如何修复此警告?

代码:

'use strict';
var React = require('react-native');
 // I have import the ScrollView and RefreshControl
var{
    StyleSheet,
    Image,
    ScrollView,
    RefreshControl,
    View,
    } = React;
var Carousel = require('react-native-looped-carousel');
var Dimensions = require('Dimensions');
var {width, height} = Dimensions.get('window');
 
var NewsListView = React.createClass({
    getInitialState: function () {

        return {

            isRefreshing: false,
            loaded: 0,

        };
    },
 
    componentDidMount: function () {
    }, 
    render: function () {
        return (
      // if I remove  RefreshControl , the warming missing. how to fix this problem
            <ScrollView
                style={styles.scrollview}
                refreshControl={
          <RefreshControl
            refreshing={this.state.isRefreshing}
            onRefresh={this._onRefresh}
            tintColor="#ff0000"
            title="Loading..."
 
          />
        }>
 
                <View>
                    <Carousel delay={5000} style={{width: width, height: height/4 }}>

                        <Image
                            source={require('RT_XiaoYiSiGou/Image/img_banner.png')
                    }
                            style={{width: width, height: height/4}}
                        />
                        <Image
                            source={require('RT_XiaoYiSiGou/Image/img_banner2.png')}
                            style={{width: width, height: height/4}}

                        />
                        <Image
                            source={require('RT_XiaoYiSiGou/Image/img_banner3.png')}
                            style={{width: width, height: height/4}}

                        />
                    </Carousel>
                </View>
            </ScrollView>
        );
    },


    _onRefresh() {
        this.setState({isRefreshing: true});
        setTimeout(() => {
            this.setState({
                loaded: this.state.loaded + 10,
                isRefreshing: false,
            });
        }, 5000);
    },

});

var styles = StyleSheet.create({
    scrollview: {
        flex: 1,
    },
});

module.exports = NewsListView;

1 个答案:

答案 0 :(得分:0)

我的“建议”是因为我无法从您的代码中执行更多操作:

1)您得到的错误是因为您未正确调用React.createElement。你应该用简单的部分编写你的代码,我建议将它分为三部分,定义,创建和渲染......

// define your element
var definitionObject = {

  // a property called render which is a function which returns your markup.
  render: function() {
    return (
      <h1 className="peterPan">
        Peter Pan.
      </h1>
    );
  }
}

// create the actual element
var PeterPanElement = React.createClass(definitionObject);


ReactDOM.render(
  <PeterPanElement />,
  document.getElementById('willBeReplacedByPeterPanElement')
);

我希望你同意我不能从你的问题中推断出更多,如果你清理问题,我们可能会帮助你更多......