• 11
name

A PHP Error was encountered

Severity: Notice

Message: Undefined index: userid

Filename: views/question.php

Line Number: 191

Backtrace:

File: /home/prodcxja/public_html/questions/application/views/question.php
Line: 191
Function: _error_handler

File: /home/prodcxja/public_html/questions/application/controllers/Questions.php
Line: 433
Function: view

File: /home/prodcxja/public_html/questions/index.php
Line: 315
Function: require_once

name Punditsdkoslkdosdkoskdo

React Native Picker not updating state

I am developing a react native app. in that i am using picker to select item and update a state. M problem is picker is not updating the state below is my code

constructor(props){
    super(props)

    this.state=({
        category:'',
    })

    getPickerElements() {
        var pickerArr = [];
        data.forEach((child, itemIndex) => {
            pickerArr.push(<Picker.Item label={child.storeName} value={child.storeId} key={itemIndex}/>)
        })

        return pickerArr;
    }

    <Picker
        selectedValue={this.state.category}

        onValueChange={(itemvalue) =>{
            this.setState({category: itemvalue})
        }}>

        {/* -------------------Dynamic Picker Data------------------ */}
        {this.getPickerElements()}
        {/* -------------------------------------------------------- */}
    </Picker>

For the record the 'data' have data and drop down working properly

onValueChange requires change in values, in case of react native we need to provide a default value (selected value) which ,ight be options from our data, or just a label item . So that every other items when picked will invoke the onvaluechange methid.

  • 1
Reply Report

It is the problem with the native picker itself. i added only one item first. the first item will not setState in react native android. when i add 2 item and select second one it worked fine

  • 0
Reply Report