React Native provides a native <TextInput /> for user data entry. By default, it is completely unstyled, appearing as an invisible field unless you look closely at the placeholder.
placeholder="Email" gives the user a hint of what to type.keyboardType="email-address" to show the @ symbol immediately, improving UX for login forms.secureTextEntry={true} prop hides characters (replacing them with dots or stars).Since inputs are used throughout the app, we extract them into a custom component that automatically respects the user's Light/Dark mode.
File: ./components/ThemedTextInput.jsx
import { TextInput, useColorScheme } from "react-native";
import { Colors } from "../constants/Colors";
const ThemedTextInput = ({ style, ...props }) => {
const colorScheme = useColorScheme();
const theme = Colors[colorScheme] ?? Colors.light;
return (
<TextInput
style={[
{
backgroundColor: theme.uiBackground,
color: theme.text,
padding: 20,
borderRadius: 6,
},
style,
]}
placeholderTextColor={theme.iconColor} // Helps visibility in both themes
{...props}
/>
);
};
export default ThemedTextInput;
useStateTo capture what the user is typing, we use Two-Way Data Binding. This means the input shows the state value, and the state updates whenever the text changes.
const [email, setEmail] = useState("");
<ThemedTextInput
placeholder="Email"
value={email}
onChangeText={setEmail} // Automatically passes the text to the setter
keyboardType="email-address"
/>
On mobile, the keyboard often stays open even if you click outside the input. To fix this, we wrap our screen in TouchableWithoutFeedback.
Keyboard.dismiss().