Abhinandan Sahgal
Abhinandan Sahgal

Reputation: 1076

ReactNative picker value resets on selection

I am working on a react native component where it has a listview with different listitems. ListItems have button on click of which it should show a reactnative pickerview . Now everything works fine except the picker resets its value when i try to select anything from picker.

Not sure if its is because of Listview,renderRow or soemthing else .

Any help will be much appreciated . Thanks

Code Snippet:-

render() {
    console.log('*** Rendeer called ***');
    return (
        <View style={styles.containerFullScreen}>
          <ListView dataSource={this.state.dataSource}
            renderRow={this.renderRow}
            renderSectionHeader={this.renderSectionHeader}>
          </ListView>

        <Picker
         mode="dropdown">
          <Picker.Item label="Java" value="java" />
          <Picker.Item label="JavaScript" value="js" />
          <Picker.Item label="Swift" value="swift" />
        </Picker>


          <TouchableHighlight
            activeOpacity={0.6}
            underlayColor={'transparent'}
            style = {styles.continueBtn}
            onPress={() => this.continueBtnAction()}>
            <Text style={styles.continueBtnText}>CONTINUE</Text>
         </TouchableHighlight>
        </View>
    );

Upvotes: 2

Views: 4179

Answers (1)

agenthunt
agenthunt

Reputation: 8678

You need to listen to onValueChange and pass the selectedValue props.

Check the Picker documentation https://facebook.github.io/react-native/docs/picker.html#picker

Upvotes: 1

Related Questions