This app shows a text input where you can type your name. Below it, it greets you with the name you typed. If you type nothing, it says "Hello, stranger!".
import React, { useState } from 'react';
import { View, TextInput, Text, StyleSheet } from 'react-native';
export default function App() {
const [name, setName] = useState('');
return (
<View style={styles.container}>
<TextInput
style={styles.input}
placeholder="Enter your name"
value={name}
onChangeText={setName}
accessibilityLabel="Name input"
/>
<Text style={styles.greeting}>Hello, {name || 'stranger'}!</Text>
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
padding: 20
},
input: {
borderColor: '#888',
borderWidth: 1,
padding: 10,
fontSize: 18,
borderRadius: 5
},
greeting: {
marginTop: 20,
fontSize: 20
}
});