2016-01-16 76 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

現在工作嗎? –

相關問題