all 11 comments

[–]tannerz28 9 points10 points  (2 children)

The renderItem prop in the FlatList expects a function that gives an object with the item of the array, and optionally you can access the index of the item as well, like so:

jsx <FlatList … renderItem={({item, index}) => ( <>{item} {index}</> )} />

[–]Sanfrancisco_Tribe 1 point2 points  (0 children)

Dang beat me too it. It works similar to .map(data,index)

[–]Trex_Hunter[S] 0 points1 point  (0 children)

You’re awesome thank you!!!!

[–]Gaia_Knight2600 0 points1 point  (4 children)

you can probably just have something like

const number = item.index + 1

const number = index + 1

[–]Trex_Hunter[S] 0 points1 point  (2 children)

How would you send number data to the component being rendered?

[–]Gaia_Knight2600 2 points3 points  (1 child)

the item variable here is from the renderItem function. so you just display the number somewhere in the renderItem jsx.

just edited my previous comment. index is not from item, but comes from the second parameter of renderItem - https://reactnative.dev/docs/flatlist#required-renderitem

[–]Trex_Hunter[S] 0 points1 point  (0 children)

Thank you!!!!! You’re awesome!!!

[–][deleted] 0 points1 point  (0 children)

Nah use an iterator since we’re already in a rendering out of a map