0

I'm learning react-native, currently learning state.

I have a TextInput on my screen:

enter image description here

however, when I try to type in it the text doesn't appear.

My code:

const Login = ({ navigation } : any) => {

    const [text, setText] = useState('');

    return (           
        <View style={[styles.container, { flexDirection: "column" }]}>
            <View style={{ flex: 1, alignItems:"center", justifyContent:"center" }}> 
                <Image source={require('../assets/images/help.png') } style={{ width: 40, height: 40 }} />
            </View>
            <View style={{ flex: 2, backgroundColor: "#5f6364", borderTopRightRadius:20, borderTopLeftRadius:20 }}> 
                <TextInput style={styles.input}  placeholder="Type here to translate!" onChangeText={newText => setText(newText)} defaultValue={text} />
            </View>            
        </View>      
    )
}

Can someone explain why this is happening?

Code Ratchet
  • 5,758
  • 18
  • 77
  • 141

1 Answers1

0

Try replacing the defaultValue with value or remove it completely

FaysalB
  • 330
  • 1
  • 11