【问题标题】:react native : value of the picker does not change反应原生:选择器的值不会改变
【发布时间】:2021-06-08 10:02:58
【问题描述】:

如果我从中选择另一个值,选择器的值不会改变 它只是在我添加 onValueChange 时发生 我很乐意为此提供帮助

const [eventType, setEventType] = useState<any>();

<Picker
                onValueChange={(itemValue, itemIndex) => { setEventType(itemValue) }}
                dropdownIconColor='black'
                mode="dropdown">
                {stateList.map(option => <Picker.Item label={option.label} key={option.key} value={option.value} />)}
            </Picker>

【问题讨论】:

  • 我认为您的Picker 上缺少value={eventType}

标签: javascript reactjs typescript react-native


【解决方案1】:

请你试试这个。我认为你应该添加你的代码 selectedValue

<Picker
                onValueChange={(itemValue, itemIndex) => { setEventType(itemValue) }}
                selectedValue={eventType}
                dropdownIconColor='black'
                mode="dropdown">
                {stateList.map(option => <Picker.Item label={option.label} key={option.key} value={option.value} />)}
            </Picker>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-05-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-01-10
    • 2019-06-14
    • 1970-01-01
    相关资源
    最近更新 更多