【问题标题】:React Native Picker only render after clickReact Native Picker 仅在单击后呈现
【发布时间】:2021-06-06 02:30:24
【问题描述】:

我在我的项目中使用@react-native-picker/picker,并且列表仅在第一次单击选择器后呈现。

<Picker
    selectedValue={"null"}
    style={{ color: "#000" }}
    onValueChange={(itemValue, itemIndex) => {
    let state = this.state;
    state.grupo = itemValue;
    this.setState(state);
    console.log(this.state.grupo);  
}}>{this.state.listaServicos.map((item, i ) => {
return <Picker.Item color="#fff" key={item.key} label={item.label} value={item.value} />
})}</Picker>

【问题讨论】:

  • 因为你设置了picker的默认值为null selectedValue={"null"}直接去掉

标签: react-native react-native-picker


【解决方案1】:

使用库文档https://github.com/react-native-picker/picker#usage中的示例

Picker 组件中的selectedValue 属性需要是状态值

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-25
    • 2021-03-08
    • 1970-01-01
    • 2017-12-05
    • 1970-01-01
    • 2021-12-05
    相关资源
    最近更新 更多