How to use string methods inside FlatList react native

Viewed 46

I need to use slice() method in my FlatList data but when I use it like below it doesn't work.

 <FlatList data={userBookings} keyExtractor={item => item.id} renderItem={itemData => (
          
   <Text style={styles.text}>{itemData.item.id.slice(3)}</Text>
.
.
.
   )
  }
/>

how can I solve this?

1 Answers
  1. I think first mistake is not to use curly brackets for callback data.
  2. Secondly you need to specify the first and last index for the .slice method

You can find the answer down below.

    <FlatList 
         data={userBookings} 
         keyExtractor={item => item.id} 
         renderItem={({itemData,index}) => ( 
              <Text style={styles.text} 
                 {itemData.item.id.slice(0,3)}
              </Text>
         )}
    />
Related