I found the example code on the Facebook React Native page, which shows how to use setNativeProp to clear text with a button, but I donβt see how to do this with multiple text fields. Here is the code:
var App = React.createClass({ clearText() { this._textInput.setNativeProps({text: ''}); }, render() { return ( <View style={styles.container}> <TextInput ref={component => this._textInput = component} style={styles.textInput} /> <TouchableOpacity onPress={this.clearText}> <Text>Clear text</Text> </TouchableOpacity> </View> ); } });
The link seems to be fixed in the function, so it will always be aimed at the same TextInput block. How can I change the function to target any TextInput field that I specify?
source share