The text does not update on the screen {account}. When you type on the text input it seems like the onChangeAccount is not called. I have destructured it but it does not work unless I put the text inside the app return statement. It types one work then dismisses the keyboard.
...
const TextInputScreen = () => {
const [account, onChangeAccount] = React.useState(null);
const ExternalTextInputContainer =({account,onChangeAccount})=>{
return(
<TextInput
style={styles.input}
onChangeText={onChangeAccount}
value={account}
/>
)
}
return (
<SafeAreaView>
/>
<Text>{account}</Text>
<ExternalTextInputContainer value={account} onChangeText={
onChangeAccount} />
</SafeAreaView>
);
};
const styles = StyleSheet.create({
input: {
height: 40,
margin: 12,
borderWidth: 1,
padding: 10,
},
});
export default TextInputScreen;
CodePudding user response:
Its because you arent passing any props to the ExternalTextInputContainer component.
Change to this:
<ExternalTextInputContainer account={account} onChangeAccount={onChangeAccount} />
CodePudding user response:
You need to pass the value to onChangeAccount. You're not passing anything to it.
<TextInput
style={styles.input}
onChangeText={text=> onChangeAccount(text)}
value={account}
/>