react-nativereact-native-textinput

How to clear the TextInput on React Native?


it is the state: const[value, setValue]= useState();

it is the code:

    <View style={styles.messaginginputContainer}>
        <TextInput
        multiline
            style={styles.messaginginput}
            onChangeText={txt => setNote(txt)}
            value={value}
        />
        <Pressable
                onPress={()=>{
            clearValue('');
        }}
        >
            <View>
                <Text style={{ color: "#f2f0f1", fontSize: 20 }}>ok</Text>
            </View>
        </Pressable>
        
    </View>

i dont know how to do this functional

Ok, i can search a little bit more, but i want to enable the vote on my account


Solution

  • This question has answer here: https://stackoverflow.com/a/45250198/13490165

    create a button, then use

    <TextInput ref={input => { textInput = input }} />
    

    and clear like this:

    textInput.clear()