react native的按钮组件不适用于android



我使用react native的button组件创建了一个按钮,但在安卓手机上按下按钮时,它不起作用。

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

按钮看起来不错,状态task没有用onChange回调更新。

尝试将TextInputonChange更新为onChangeText

<TextInput 
placeholder='Task' 
style={style.inputBox}
onChangeText={setTask} 
value={task}
/>

最新更新