React - Flatlist doesn't render anything

kilinkis

I have a React-Native project that renders a list of items.

I was using .map function to do it but since I'll have several items in the future, I'm trying to migrate the function to flatlist.

The documentation provided by React is quite simple, yet I can't get it to work. Any ideas why?

here's my code:

renderEtiquetas() {

        // this commented code works just fine
        // return this.props.etiquetas.map(etiqueta =>
        //   <EtiquetaDetail key={etiqueta.id} etiqueta={etiqueta} galleries={ this.props.galleries } />
        // );

        <FlatList
          data={ this.props.etiquetas }
          keyExtractor={etiqueta => etiqueta.id}
          renderItem={({ etiqueta }) => (
            <EtiquetaDetail key={etiqueta.id} etiqueta={etiqueta} galleries={ this.props.galleries } />
          )}
        />

  }

here is the content for this.props.etiquetas has this format: [{…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}] and here is one of the objects in it: {id: 523, date: "2014-04-16T16:30:03", date_gmt: "2014-04-16T16:30:03", modified: "2018-01-13T00:00:43"}

Thanks for your time!

kilinkis

The problem was that I was missing the return word before https://facebook.github.io/react-native/docs/flatlist.html Also, I tried extraData={this.state} but didn't do anything.

Thanks @Chao Chen for answering!

Este artigo é coletado da Internet.

Se houver alguma infração, entre em [email protected] Delete.

editar em
0

deixe-me dizer algumas palavras

0comentários
loginDepois de participar da revisão

Artigos relacionados