skip to Main Content

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

2

Answers


  1. 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()
    
    Login or Signup to reply.
  2. The easiest way to clear any text input is by clearing the state like this :

    import { TouchableOpacity , TextInput } from 'react-native';
    
    const [ inputValue , setInputValue ] = useState<string>("")
    
    const clearInputValue = (): void => setInputValue("")
    
    return (
        <>
           <TextInput value={inputValue} onChangeText={value => setInputValue(value)} />
           <TouchableOpacity onPress={clearInputValue}>Clear Input value</TouchableOpacity>
        </>
    )
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search