Home > Software design >  Unable to render flatlist items in a row
Unable to render flatlist items in a row

Time:05-04

I am using flat list to render some data from faker js, everything works when I am using default flexDirection: "column" rendering type, however I want to render the items in row and this code does not work.

    <FlatList
      style={{
        flexDirection: "row",
        flexWrap: "wrap"
      }}
      data={fakePeople}
      renderItem={renderItem}
      keyExtractor={(item) => item.fullName}
    />

Nothing is being rendered, but as soon as I take the flexDirection: "row", everything works fine.

Here is a link for the demo

https://codesandbox.io/s/nifty-galois-5zpnp1?file=/src/App.js:718-916

Is this a bug or does React native flatlist does not support row layout?

CodePudding user response:

Use the horizontal prop like this,

<FlatList
  horizontal
  data={fakePeople}
  renderItem={renderItem}
  keyExtractor={(item) => item.fullName}
/>

Or if you want several items per column

<FlatList
  numColumns={3}
  data={fakePeople}
  renderItem={renderItem}
  keyExtractor={(item) => item.fullName}
/>

CodePudding user response:

You must use horizontal FlatList prop as documentation says , and if you want to make some like grid layout you can use numColumns prop https://reactnative.dev/docs/flatlist#numcolumns

I edited a few your codesandbox

  • Related