In Code below, the onSubmitEditing event triggers on every key press. Strangely, if I ment out the onChangeText event, onSubmitEditing somestimes seems to trigger, as appropriate, only on return.
Is someone able to explain how I would either, (a) get onSubmitEditing to trigger appropriately even when onChangeText is called, or (b) retrieve the value of the text input in onSubmitEditing event.
render() {
return (
<View style={styles.container}>
<TextInput
onChangeText={text => this.setState({ text })}
onSubmitEditing={
console.log(`onSubmitEditing: ${this.state.text}`)
}
placeholder="Enter Text..."
returnKeyType="done"
returnKeyLabel="done"
/>
</View>
);
}
I am using
"expo": "^32.0.0",
"react": "16.5.0",
"react-native": "0.57.1",
Thanks!
UPDATE: This seems to work
onSubmitEditing={a => console.log(`onSubmitEditing: ${this.state.text}`) }
Can someone help me understand what is going on?
In Code below, the onSubmitEditing event triggers on every key press. Strangely, if I ment out the onChangeText event, onSubmitEditing somestimes seems to trigger, as appropriate, only on return.
Is someone able to explain how I would either, (a) get onSubmitEditing to trigger appropriately even when onChangeText is called, or (b) retrieve the value of the text input in onSubmitEditing event.
render() {
return (
<View style={styles.container}>
<TextInput
onChangeText={text => this.setState({ text })}
onSubmitEditing={
console.log(`onSubmitEditing: ${this.state.text}`)
}
placeholder="Enter Text..."
returnKeyType="done"
returnKeyLabel="done"
/>
</View>
);
}
I am using
"expo": "^32.0.0",
"react": "16.5.0",
"react-native": "0.57.1",
Thanks!
UPDATE: This seems to work
onSubmitEditing={a => console.log(`onSubmitEditing: ${this.state.text}`) }
Can someone help me understand what is going on?
Share Improve this question edited Jan 23, 2019 at 16:03 marc-dworkin asked Jan 23, 2019 at 15:46 marc-dworkinmarc-dworkin 3364 silver badges16 bronze badges 1-
2
onSubmitEditing
takes afunction
as a argument. Before you were passing an expression. – johnborges Commented Jan 23, 2019 at 16:07
1 Answer
Reset to default 8simply because onSubmitEditing
is a prop that expecting a function call. When you're doing this onSubmitEditing={console.log('a')}
, you're missing the binding and so the reason it's working after you implemented in arrow function