React native &引用;Undefined不是对象(计算';child.props.value';”);react native中的选择器组件出错

React native &引用;Undefined不是对象(计算';child.props.value';”);react native中的选择器组件出错,react-native,react-native-android,React Native,React Native Android,我在使用选择器组件时遇到了以下错误: <Picker style={{ flex: 1 }}> selectedValue={this.props.shift} onValueChange={value => this.props.employeeFormAction({ prop:'shift', value })} > <Pick

我在使用选择器组件时遇到了以下错误:

<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> 

selectedValue={this.props.shift}
onValueChange={value=>this.props.employeeFormAction({
属性:'shift',value}}
>   
我已经厌倦了这个来自同一个社区的解决方案


但这对我不起作用。任何机构都可以为这个问题提出解决方案。

尽量不要硬编码这些值。这样更干净:

// inside your component (supposing is not a functional component)
_renderShifts = () => {
  const shifts = ['Monday', 'Tuesday', 'Wednesday','Thursday',
                'Friday','Saturday', 'Sunday'];

  return shifts.map((shift) => {
    <Picker.Item key={"shift_"+i} label={shift} value={shift} />
  });
}


// now your picker should render this way
_renderPicker = () => {
  <Picker 
    style={{ flex: 1 }}>
    selectedValue={this.props.shift}
    onValueChange={value => this.props.employeeFormAction({prop:'shift', value })}
  >   
    {this._renderShifts()}
  </Picker>
}
//组件内部(假设不是功能组件)
_渲染移位=()=>{
常量班次=[“星期一”、“星期二”、“星期三”、“星期四”,
“星期五”、“星期六”、“星期日”];
返回移位。映射((移位)=>{
});
}
//现在,您的选择器应该以这种方式渲染
_renderPicker=()=>{
selectedValue={this.props.shift}
onValueChange={value=>this.props.employeeFormAction({prop:'shift',value})}
>   
{this._rendershift()}
}

导入选择器而不进行相应的对象分解时,也会返回此错误

不正确

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

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

尝试设置选择器项的键。@vijayst,即使将键添加到选择器项,也没有结果。有其他选择吗?即使我删除了硬编码的值,我仍然面临同样的错误。您是否可以建议任何替代方案?您是否可以建议任何替代方案,因为我仍然面临问题。您是否使用redux来管理更改,如果this.props.shift未定义,您是否可以尝试和console.log?顺便说一句,你给它Flex1是出于某种特殊的原因吗?问题在于react本机版本。它在0.48中不起作用,但在0.49中效果很好。还有一件事是,没有显示“flex:1”或“flexDirection:row或column”的选择器。在这种情况下,我无法为选择器放置标签。你能帮我一下吗?只是为了记录在案,如果它在RN 0.49上运行良好,为什么不直接使用RN 0.49呢?您是否考虑过要使用flex,您需要在父组件中定义高度?也许问题不在于选择器,而在于周围的代码。