Ich habe eine Schaltfläche mit der Button-Komponente von React-Native erstellt, aber beim Drücken der Schaltfläche auf einem Android-Telefon funktioniert sie nicht.
import react,{useState} from 'react';
import { View,Text,TextInput,StyleSheet,Button } from 'react-native';
const Form=({addTask})=>{
const [task,setTask] = useState('')
const onTaskAdd=()=>{
if(!task) return
addTask(task)
}
return (
<View style={style.formContainer}>
<TextInput
placeholder='Task'
style={style.inputBox}
onChange={e=>setTask(e.target.value)}/>
<Button
onPress={onTaskAdd}
title="Learn More"
color="#841584"
accessibilityLabel="Learn more about this purple button"
/>
</View>
)
}
export default Form
Lösung des Problems
Die Schaltfläche scheint in Ordnung zu sein, der Status task
wird nicht mit Ihrem onChange
Rückruf aktualisiert.
Versuchen Sie, TextInput
onChange auf onChangeText zu aktualisieren
<TextInput
placeholder='Task'
style={style.inputBox}
onChangeText={setTask}
value={task}
/>
Keine Kommentare:
Kommentar veröffentlichen