“未定义不是对象(评估'child.props.value')”与react-native中的Picker组件的错误

时间:2017-10-04 06:33:38

标签: react-native react-native-android

当我使用Picker组件时,我遇到了这个错误,

<Picker 
   style={{ flex: 1 }}>
   selectedValue={this.props.shift}
   onValueChange={value => this.props.employeeFormAction({ 
                                             prop:'shift', value })}
>   
        <Picker.Item label='Monday' value='Monday' />
        <Picker.Item label='Tuesday' value='Tuesday' />
        <Picker.Item label='Wednesday' value='Wednesday' />
        <Picker.Item label='Thursday' value='Thursday' />
        <Picker.Item label='Friday' value='Friday' />
        <Picker.Item label='Saturday' value='Saturday' />
        <Picker.Item label='Sunday' value='Sunday' />
</Picker> 

我已经厌倦了来自同一社区的解决方案

react-native - Picker - undefined is not an object (evaluating 'this.props.children[position].props)

但它对我不起作用。任何机构都可以就此问题提出解决方案。

2 个答案:

答案 0 :(得分:1)

尽量不对值进行硬编码。这种方式更清洁:

 NSError* error = nil;
 NSData *uploadFileData = [NSData dataWithContentsOfFile:UploadfilePathString  options:0 error:&error];
    NSLog(@"Data read from %@ with error: %@", uploadFileData, error);

答案 1 :(得分:1)

在导入Picker而不破坏相应对象的情况下,也会返回此错误。

不正确

import Picker from '@react-native-community/picker'

正确

import { Picker } from '@react-native-community/picker'