Handling Event, Input, dan Form Validation
Error Messages
Menampilkan pesan error yang jelas, spesifik, dan membantu pengguna memperbaiki input.
import { Text } from "react-native";
const FormInput = ({ value, onChangeText, error, placeholder }) => {
return (
<>
<TextInput
value={value}
onChangeText={onChangeText}
placeholder={placeholder}
style={[styles.input, error && styles.inputError]}
/>
{error && <Text style={styles.errorText}>{error}</Text>}
</>
);
};
const styles = StyleSheet.create({
input: {
borderWidth: 1,
borderColor: "#ccc",
padding: 10,
},
inputError: {
borderColor: "red",
},
errorText: {
color: "red",
fontSize: 12,
marginTop: 5,
},
});