I'm working on an app which the users will enter large number of records continuously. Currently, I'm using State to clearing the input when submit is pressed. So by considering performance issues i'd like to clear the input using ref property. So i've tried by using these.
1- firstref.current.clear();
2- firstref.current.setNativeProps({ text: '' });
3- firstref.current.value = '';
But the input field is not clearing the value after submit. I'm using a custom input component. Here is a demo by clearing the input using state. Demo using state
<View style={styles.fixedform}>
<View style={styles.textinputViewleft}>
<TextInput
style={styles.textinput}
ref={firstref}
label="Digit"
returnKeyType="next"
value={digit.value}
onChangeText={(text) => { setDigit({ value: text, error: '' }); if (text.length === 3) { ref.current.focus(); } }}
error={!!digit.error}
errorText={digit.error}
keyboardType="numeric"
maxLength={3}
minLength={3}/>
</View>
<View style={styles.textinputView}>
<TextInput
style={styles.textinput}
ref={ref}
label="Count"
value={count.value}
onChangeText={(text) => setCount({ value: text, error: '' })}
error={!!count.error}
errorText={count.error}
keyboardType="numeric"
maxLength={3}/>
</View>
<View style={styles.textinputView}>
<Button loading={loading} disabled={disabled} style={styles.buttonView} mode="contained" onPress={onSubmitPress}>Submit</Button>
</View>
</View>