import React from 'react';
import { View, Text, SectionList, StyleSheet } from 'react-native';
export default function GroupedContacts() {
const sections = [
{ title: 'A', data: ['Alice', 'Aaron'] },
{ title: 'B', data: ['Bob', 'Brenda'] },
{ title: 'C', data: ['Charlie', 'Clara'] }
];
return (
<View style={styles.container}>
<SectionList
sections={sections}
keyExtractor={(item, index) => item + index}
renderItem={({ item }) => <Text style={styles.item}>{item}</Text>}
renderSectionHeader={({ section: { title } }) => (
<Text style={styles.header}>{title}</Text>
)}
/>
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
marginTop: 40,
paddingHorizontal: 20
},
header: {
fontSize: 24,
fontWeight: 'bold',
backgroundColor: '#eee',
paddingVertical: 5
},
item: {
fontSize: 18,
paddingVertical: 5
}
});This app uses React Native's SectionList to display contacts grouped by their first letter.
The sections array contains objects with a title for the group header and a data array for the contacts in that group.
The renderSectionHeader shows the group letter in bold with a light background.
The renderItem shows each contact name with some padding.
This structure makes it easy to show grouped lists like contacts or categories.