Component not showing in react native

Viewed 83

I have a FlatList that renders a component called featured for each item in the list. I have several items in the list. However, the list isn't showing. Here's the code, and the flatlist has the renderItem called renderItem which returns the Featured component that we want to display:

import * as React from 'react';
import { FlatList, StyleSheet, TextInput, Image, Button, Pressable } from 'react-native';
//import { connect } from 'react-redux';
import EditScreenInfo from '../components/EditScreenInfo';
import { Text, View } from '../components/Themed';
import Featured from '../components/Featured';
//import getFeatured from "../"
export default function TabOneScreen(props) {
    const renderItem = ({item}) => {
      return (<Featured
        artistName= {item.artistName}
        mediaName= {item.mediaName}
        uri={item.uri}
        />
        );}
    // useEffect(() => {
    //   getFeatured();
    // })
    return (
      <View style={styles.container}>
        <Text style={styles.title}>Discover Music to Own</Text>
        <View style={styles.separator} lightColor="#eee" darkColor="rgba(255,255,255,0.1)" />
          <TextInput style={styles.searchbar}
          placeholder="Search Music to Own"/>
          <FlatList
          data={props.featured}
          renderItem={renderItem}
          keyExtractor={item => item.mediaName}/>
      </View>
  )
}


const featured = [{uri:"https://i.guim.co.uk/img/media/68659a5732b6a11833ad642325c94276e73bfd17/1518_282_1533_920/master/1533.jpg?width=1200&height=900&quality=85&auto=format&fit=crop&s=55a7cd37c94dacf41f82d43e83352818",
                   artistName:"Beyonce",
                   mediaName:"Good Album Name",
                   videoUri:'http://d23dyxeqlo5psv.cloudfront.net/big_buck_bunny.mp4'
                 },
                  {uri:"https://i.guim.co.uk/img/media/68659a5732b6a11833ad642325c94276e73bfd17/1518_282_1533_920/master/1533.jpg?width=1200&height=900&quality=85&auto=format&fit=crop&s=55a7cd37c94dacf41f82d43e83352818",
                   artistName:"Beyonce",
                   mediaName:"Good Album Name1",
                 videoUri:'http://d23dyxeqlo5psv.cloudfront.net/big_buck_bunny.mp4'
               },
                  {uri:"https://i.guim.co.uk/img/media/68659a5732b6a11833ad642325c94276e73bfd17/1518_282_1533_920/master/1533.jpg?width=1200&height=900&quality=85&auto=format&fit=crop&s=55a7cd37c94dacf41f82d43e83352818",
                   artistName:"Beyonce",
                   mediaName:"Good Album Name2",
                 videoUri:'http://d23dyxeqlo5psv.cloudfront.net/big_buck_bunny.mp4'
               }]

How to show the list?

1 Answers

I've used your local featured variable for rendering FlatList, it worked fine for me, Please check you're passing featured in your props or not . I remove some of your local components to make it work.

import * as React from 'react';
import { FlatList, TextInput, Text, View } from 'react-native';

export default function App(props) {
  const renderItem = ({ item }) => {
    return (<Text>{item.artistName}</Text>);
  };

  return (
    <View>
      <Text>Discover Music to Own</Text>
      <View />
      <TextInput
        placeholder="Search Music to Own" />
      <FlatList
        data={featured}
        renderItem={renderItem}
        keyExtractor={item => item.mediaName} />
    </View>
  );
}


const featured = [{
  uri: "https://i.guim.co.uk/img/media/68659a5732b6a11833ad642325c94276e73bfd17/1518_282_1533_920/master/1533.jpg?width=1200&height=900&quality=85&auto=format&fit=crop&s=55a7cd37c94dacf41f82d43e83352818",
  artistName: "Beyonce",
  mediaName: "Good Album Name",
  videoUri: 'http://d23dyxeqlo5psv.cloudfront.net/big_buck_bunny.mp4'
},
{
  uri: "https://i.guim.co.uk/img/media/68659a5732b6a11833ad642325c94276e73bfd17/1518_282_1533_920/master/1533.jpg?width=1200&height=900&quality=85&auto=format&fit=crop&s=55a7cd37c94dacf41f82d43e83352818",
  artistName: "Beyonce",
  mediaName: "Good Album Name1",
  videoUri: 'http://d23dyxeqlo5psv.cloudfront.net/big_buck_bunny.mp4'
},
{
  uri: "https://i.guim.co.uk/img/media/68659a5732b6a11833ad642325c94276e73bfd17/1518_282_1533_920/master/1533.jpg?width=1200&height=900&quality=85&auto=format&fit=crop&s=55a7cd37c94dacf41f82d43e83352818",
  artistName: "Beyonce",
  mediaName: "Good Album Name2",
  videoUri: 'http://d23dyxeqlo5psv.cloudfront.net/big_buck_bunny.mp4'
}]
Related