Skip to content

PickerIOS selectedValue reset when change value #25352

Description

@AlexiaTorres

When I change selected option, it resets to first.
For example if this.props.center is C and i have:
A
B
C <-
D
E

I start with C selected, i change to E for example, state on console.log is E but it shows A selected.

React Native version:
0.57.1

Here is my code:

constructor(props) {
        super(props);
        this.state = {
            selectedCenter: this.props.center
        };
    }

    render() {
        if (this.props.centers) {
            return (
                <View style={{backgroundColor: '#008590d9'}}>
                    <PickerIOS
                        selectedValue={this.state.selectedCenter}
                        style={styles.select}
                        onValueChange={(itemValue, itemIndex) => {
                            console.log(itemValue);
                            this.setState({selectedCenter: itemValue});
                        }}>
                        {
                            this.props.centers.map((center) => {
                                console.log(this.state.selectedCenter);
                                return <PickerIOS.Item key={center.id} title={center.name} label={center.name}
                                                       value={center}/>
                            })
                        }
                    </PickerIOS>
                </View>
            )
        }
    }

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugComponent: PickerIOSPlatform: iOSiOS applications.StaleThere has been a lack of activity on this issue and it may be closed soon.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions