2017-03-26 55 views
0

我已经开始使用React和Google Books API开发图书搜索应用程序。然而,当我读模拟器我已经遇到了一个错误:React Native元素类型无效使用ActivityIndi​​catorIOS时出错Error

Element Type is invalid: expected a string (for built-in components) or 
a class/function (for composite components) but got: undefined. Check 
the render method of 'BookList'. 

考虑到我是相当新的反应,我希望有人也许能够在下面我的代码来指出错误(或多个)。我注意到我认为可能有错误的地方。谢谢!

class BookList extends React.Component { 
    constructor(props) { 
     super(props); 
     this.state = { 
      isLoading: true, 
      dataSource: new ListView.DataSource({ 
       rowHasChanged: (row1, row2) => row1 !== row2 
      }) 
     }; 
    } 

    componentDidMount() { 
     this.fetchData(); 
    } 

    fetchData() { 
     fetch(REQUEST_URL[0]) 
     .then((response) => response.json()) 
     .then((responseData) => { 
      this.setState({ 
       dataSource: this.state.dataSource.cloneWithRows(responseData.items), 
       isLoading: false 
      }); 
     }) 
     .done(); 
     } 

    render() { 
     if (this.state.isLoading) { 
      return this.renderLoadingView(); 
     } 

    return (
     <ListView 
      dataSource={this.state.dataSource} 
      renderRow={this.renderBook.bind(this)} 
      style={styles.listView} 
      /> 
     ); 
    } 

// *** adding this function (and using it) began to cause issues **** 

    renderLoadingView() { 
     return (
      <View style={styles.loading}> 
       <ActivityIndicatorIOS 
        size='large'/> 
       <Text> 
        Loading books... 
       </Text> 
      </View> 
     ); 
    } 

    renderBook(book) { 
     return (
      <TouchableHighlight> 
       <View> 
        <View style={styles.container}> 
         <Image 
          source={{uri: book.volumeInfo.imageLinks.thumbnail}} 
          style={styles.thumbnail} /> 
        <View style={styles.rightContainer}> 
         <Text style={styles.title}>{book.volumeInfo.title}</Text> 
         <Text style={styles.author}>{book.volumeInfo.authors}</Text> 
         <Text style={styles.price}>{'Lowest Available Price: ' + book.volumeInfo.price}</Text> 
        </View> 
       </View> 
       <View style={styles.separator} /> 
      </View> 
     </TouchableHighlight> 
    ); 
} 
} 

var REQUEST_URL = ['https://www.googleapis.com/books/v1/volumes?q=subject:fiction']; 

回答

相关问题