import React from 'react';
import { View, Text, StyleSheet } from 'react-native';
function UserInfoCard({ name, email }) {
return (
<View style={styles.card}>
<Text style={styles.name}>Name: {name}</Text>
<Text style={styles.email}>Email: {email}</Text>
</View>
);
}
export default function ProfileScreen() {
return (
<View style={styles.container}>
<UserInfoCard name="John Doe" email="john@example.com" />
<UserInfoCard name="Jane Smith" email="jane@example.com" />
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
padding: 20,
backgroundColor: '#fff'
},
card: {
borderWidth: 1,
borderColor: '#ccc',
padding: 15,
marginBottom: 15,
borderRadius: 5
},
name: {
fontWeight: 'bold',
marginBottom: 5
},
email: {
color: '#555'
}
});We created a new component UserInfoCard that takes name and email as inputs (props). This component shows the user info inside a styled box with a border and padding.
Then, inside ProfileScreen, we used UserInfoCard two times with different user data. This way, the code is clean and reusable.
The styles add spacing and borders to make the cards look neat and separated.