Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Picker : undefined is not an object :child.props.value #983

Closed
nooralahzadeh opened this issue Jun 24, 2017 · 27 comments
Closed

Picker : undefined is not an object :child.props.value #983

nooralahzadeh opened this issue Jun 24, 2017 · 27 comments
Labels

Comments

@nooralahzadeh
Copy link

nooralahzadeh commented Jun 24, 2017

I am trying to return Picker.Item from an array but I face the following error:

undefined is not an object :child.props.value
<Picker style={{ paddingLeft: 100, width:(Platform.OS === 'ios') ? undefined : 120 }}
iosHeader="Selecy"
mode="dropdown"
selectedValue="0"
inLineLabel={true}>
<Picker.Item label="Item 0" value="0" />
{this.props.ItemList.map((member,key)=>{
<Picker.Item label={member.props} value={member.value} />
})
}
</Picker>

@luoyjx
Copy link

luoyjx commented Jun 24, 2017

+1

@horiuchie
Copy link

horiuchie commented Jun 24, 2017

I guess that will happen in the following cases:

A) rendering just one
Ref: #921

  <Picker ...>
    <Picker.Item ... />
  </Picker>

B) rendering one and an array of items

  <Picker ...>
    <Picker.Item ... />
    {
      this.props.ItemList.map((member, key) => <Picker.Item ... />)
    }
  </Picker>

C) not returning element in callback

<Picker ...>
  {
    this.props.ItemList.map((member, key) => {
      // either use return statements or does not use brackets
      // one more thing, use key attribute if rendering from an array
      <Picker.Item key={key} ... />
    })
  }
</Picker>

@nooralahzadeh
Copy link
Author

@horiuchie so this is a bug!

@horiuchie
Copy link

horiuchie commented Jun 24, 2017

I agree.
As a workaround, it might work if put your ”Item0” into the array, then make the callback returns element.

@nooralahzadeh
Copy link
Author

@horiuchie Thanks , I make it by using C) not using the brackets and puting the Item0 in the array

@horiuchie
Copy link

horiuchie commented Jun 24, 2017

sure :)
I hope that B) will be fixed someday because it's a common way of rendering, though I don't think high priority.

screenshot
issue

@lukewlms
Copy link

This appears to be a fairly strong limitation.

We want to have a dropdown that must be selected, meaning when it starts it says "Select a value..."

In Android, the "placeholder" property is not supported on Native Base so we have to include this item at the top of the list; however because of the limitation in this issue that is impossible. Currently we have no workaround for this.

@shivrajkumar
Copy link
Collaborator

shivrajkumar commented Jul 26, 2017

NativeBase picker for android is a direct implementation of react-native's picker. Since React Native Picker doesn't have this yet, there is no way of doing this as of now.

@lukewlms
Copy link

@shivrajkumar This does appear to be a NativeBase bug - this type of example from @horiuchie
works fine for us in React Native on Android but breaks in NativeBase:

B) rendering one and an array of items

  <Picker ...>
    <Picker.Item ... />
    {
      this.props.ItemList.map((member, key) => <Picker.Item ... />)
    }
  </Picker>

@sankhadeeproy007
Copy link
Contributor

Hi @lukecwilliams, this is our implementation of the picker. Are we missing something here?

@lukewlms
Copy link

That looks pretty straightforward.

This code without the first NBPicker.Item works for us, but with the first NBPicker.Item breaks. I'm not sure why @horiuchie indicated this situation should break - I'm not aware of why that would be the case, but it does break for us. Sorry I can't be of more help. Unfortunately, in RN we get a generic "shadowView super (of ID 76) not found" error that doesn't help us debug.

        <NBPicker
          iosHeader="Select one"
          mode="dropdown"
          placeholder="Select a workout"
          onValueChange={(value: string) => "testing" }
        >
          <NBPicker.Item key={ "someKey" }
            label={ "Select one..." }
            value={ "someValue" } />;
          {
            this.props.userData.standardWorkoutDefinitions.edges
              .map((edge: any) => {
                console.log(edge.node.id);
                return <NBPicker.Item key={ edge.node.id }
                  label={ edge.node.description }
                  value={ edge.node.id } />;
                },
              )
          }
        </NBPicker>

@xanderdeseyn
Copy link

xanderdeseyn commented Jul 29, 2017

We are running into the same problem here, while simply using map:

<Picker
        iosHeader={ this.props.selectionText ? this.props.selectionText : "Select" }
        mode="dropdown"
        selectedValue={this.state.selected}
        onValueChange={this.onValueChange.bind(this)}
      >
        { this.props.values.map( value => (<Picker.Item key={value} label={value} value={value} />) ) }
</Picker>

Anyone found a solution yet?

@xanderdeseyn
Copy link

We found the solution... the bug is quite incredible really.

We are using ImmutableJS for our redux state. this.props.values is an immutable list. When you go and look at the source code of Picker.ios.js, you see that it is using lodash's find function. Apparently, they can't handle an immutable list even though it works throughout the rest of React Native.

The (ugly) solution is thus:
{ this.props.values.toArray().map( value => (<Picker.Item key={value} label={value} value={value} />) ) }

@Suraj-Tiwari
Copy link

Suraj-Tiwari commented Jan 4, 2018

Recently I've faced the same issue, This might be a less ugly solution
This is hapenning because of this

<Picker.Item label="Item 0" value="0" /> /// **<- Issue is here due to this hard coded Item** 
{this.props.ItemList.map((member,key)=>{<Picker.Item label={member.props} value{member.value} />
})
render() {
  return (
    <Picker mode='dropdown' selectedValue={selectedValue} onValueChange={onValueChange} >
      { make_list(['pass','your','desire','list']) }
    </Picker>
  )}
function make_list(list){
        d = list.map((data,i) => {
            return (
                <Picker.Item label={data} value={i}/>
            )
        })
       // i did this because no need in ios :P 
        if(Platform.OS === 'android'){
            d.unshift(<Picker.Item label="Select" />)
        }
        return d;
      //and that's how you are ready to go, because this issue isn't fixed yet (checked on 28-Dec-2017)
 }

@kodamirmo
Copy link

Any update?

@vbspace
Copy link

vbspace commented Feb 15, 2018

any updates ?

@ahmadsyamim
Copy link

any update here?

@SupriyaKalghatgi
Copy link
Contributor

Fixed with 2.7.1

@ap050492
Copy link

Facing same issue...


<Picker
  mode="dropdown"
  placeholder="Choose One"
  textStyle={style.pickerTextTyle}
  selectedValue={this.state.categoryValue}
  style={style.pickerStyle}
  onValueChange={this.onValueChangeDD.bind(this,1)}
  headerTitleStyle={style.pickerHeaderTitleStyle}>
      <Item label="Item 0" value="0" />
      {this.state.categoryData.map((member, key) => {
            <Item label={member.value} value={member.value} />
        })
      }
</Picker>

@akhil-ga
Copy link
Contributor

@ap050492 the map function misses return statement.

Change this

 {this.state.categoryData.map((member, key) => {
            <Item label={member.value} value={member.value} />
        })
      }

to

{this.state.categoryData.map((member, key) => 
            <Item label={member.value} value={member.value} key={key}/>
        )
      }

or

{this.state.categoryData.map((member, key) => {
           return <Item label={member.value} value={member.value} key={key}/>
        })
      }

@ranjanpoudel1234
Copy link

Thanks @akhil-geekyants for the solution, the last one worked great for me. Was missing the return

@marcocesarato
Copy link

marcocesarato commented Aug 7, 2019

After upgrade from version 2.12.2 to 2.13.4 I've this issues.

My code is like this format:

{this.state.categoryData.map((member, key) => {
           return (<Picker.Item label={member.value} value={member.value} key={key}/>)
        })
}

@sentry0
Copy link

sentry0 commented Aug 8, 2019

Same issue with 2.13.4, only on iOS in my case, Android works fine.

@aminalali8
Copy link

Why is this closed I'm still facing the same issue here

@Flip32
Copy link

Flip32 commented Aug 11, 2020

I'm using expo: 38, and native-base: 2.13.13
This problem still happening on IOS.
I tried all methods in this page unsuccessfuly

@nikhilarora18
Copy link

I was also getting the same error and the issue in my code was that I was rendering a Picker.Item conditionally and when the condition failed it was returning undefined, hence the error undefined is not an object.
So, make sure if you want conditional items, then make a array and return the array inside Picker without any undefined entry.

@cngodles
Copy link

Going to add this here. Not sure if this will answer it for anyone, but it seemed to work for some people.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests