Ad

React.createElement : Type Should Not Be Null

- 1 answer

I copied the code from here.

This throws this warning:

warning.

How to fix this warning?

Code:

'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;

Ad

Answer

What I "suggest" because I can't do more from your code is:

1) The error you get is because you do not call the React.createElement correctly. You should write your code in simple segments, I suggest chopping it up in three parts, definition, creation and render...

// 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')
);

I hope you agree I can't deduce more from your question, if you clean the question up we might be able to help you out more...

Ad
source: stackoverflow.com
Ad