首页 > 解决方案 > react-native-dropdown-picker 回到屏幕时会留下占位符吗?

问题描述

我正在做 react-native 项目。我对这个库“react-native-dropdown-picker”有疑问。当我在其下拉列表中选择某个值时,它将占位符留下我选择的值,我再次回到同一屏幕上。下面是代码。

sourceListArry=[[
    {
      "label": "ABC",
      "value": "SourceBody"
    },
    {
      "label": "EFG",
      "value": "SourceBody"
    }
  ]]
callFun = async (item) => {
    await AppStorage.saveKey(key.GET_SOURCE, JSON.stringify(item.label)).then(() => {
    })
  }

<DropDownPicker
                      items={sourceListArry}
                      placeholder={'Source'}
                      containerStyle={{
                        height: hp('6%'),
                        width: '100%'
                      }}
                      itemStyle={{
                        height: hp('5%'),
                        width: '100%',
                        justifyContent: 'flex-start'
                      }}
                      onOpen={() => Keyboard.dismiss()}
                      onChangeItem={item => this.callFun(item)}
                      dropDownStyle={{ backgroundColor: '#E0E0E0' }}
                      dropDownMaxHeight={130}
                      onOpen={() => Keyboard.dismiss()}
                      labelStyle={{
                        fontSize: hp('1.6%'),
                        textAlign: 'left',
                        color: '#000'
                      }}
                    />

当我回到屏幕上时,它的占位符保持不变,这是我最后选择的。但不是默认的 - 在其 UI 上再次“排序”。请让我知道一些解决方案,我将不胜感激。

标签: reactjsreact-nativereact-reduxreact-hooks

解决方案


推荐阅读