2016-01-16 39 views
1

我复制了here中的代码。React.createElement:类型不能为空

这将引发此警告:

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

我 “建议”,是因为我无法从你的代码做更多的是:

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

我希望你同意,如果你干净,我不能推断出更多的从你的问题,问题了,我们可能能够帮助你更多...

+0

eh.I;对不起。我编辑的排队。我有createClass并有定义,创建和渲染。 –

+0

现在工作吗? –

相关问题