简体   繁体   中英

can't find method in react native component class

Hi I am new to react native and playing with their methods. I have declared albumCards method but Its giving me issues during runtime.

import React, { Component } from 'react';
import { Text, ScrollView, View, ActivityIndicator } from 'react-native';
import axios from 'axios';
import AlbumDetail from './albumDetail';

class AlbumList extends Component {
  state = { albums : [] };

  albumCards() {
    return this.state.albums.map(album =>
      <AlbumDetail key={album.title} album={album}/>
    );
  }

  renderAlbums() {
    if (this.state.albums.length > 0) {
      return <ScrollView> { albumCards() } </ScrollView>
    } else {
      return  <ActivityIndicator size="large" color="#0000ff" />
    }
  }

  render() {
    console.log(this.state);
    return (
      <View style = {styles.containerStyle}>
        {this.renderAlbums()}
      </View>
    );
  };
}


export default AlbumList;

I am getting the below error in the screenshot as albumscards could not be found. Could anyone please help.

在此处输入图片说明

您需要像这样调用函数。

<ScrollView> { this.albumCards } </ScrollView>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM