'Button component of react native not working on android

I created a button using the Button component of react-native, but while pressing the button on an android phone it's not working.

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


Solution 1:[1]

The button seems fine, the state task is not getting updated with your onChange callback.

Try updating TextInput onChange to onChangeText

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

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 imKrishh