I have a functional component in which I am trying to clear a TextInput on submit. Sometimes the onChangeText callback is called after onSubmitEditing, so the input is not clear after submitting. Most often this happens due to autocorrect, but sometimes happens with random strings that were not autocorrected. How do I make sure the input is cleared consistently?
Code: https://snack.expo.io/hy4dKvvnr
export default function App() {
const [inputValue, setInputValue] = useState('');
return (
<View style={styles.container}>
<TextInput
style={styles.input}
value={inputValue}
onChangeText={(value) => {
console.log('CHANGE TEXT', value);
setInputValue(value);
}}
blurOnSubmit
onSubmitEditing={() => {
console.log('SUBMIT TEXT');
setInputValue('');
}}
/>
</View>
);
}
Console logs:
iPhone 8: CHANGE TEXT Kdjgw
iPhone 8: SUBMIT TEXT
iPhone 8: CHANGE TEXT Kdjgw