反应本机社区选择器不显示任何内容且无法打开

问题描述

我正在使用React Native社区选择器。我在选择器中看不到任何东西或将其打开。

const Item = Picker.Item as any;
    
    function ActivityPicker() {
        const [value,setValue] = React.useState('key1');
        return (
          <View>
            <Picker
              testID="basic-picker"
              selectedValue={value}
              onValueChange={(v) => setValue(v)}>
              <Item label="hello" value="key0" />
              <Item label="world" value="key1" />
            </Picker>
          </View>
        );
    }

也看到这种错误

 Argument of type 'ReactText' is not assignable to parameter of type 'SetStateAction<string>'.
  Type 'number' is not assignable to type 'SetStateAction<string>

解决方法

我建议让选择器显示的第一件事是定义一些尺寸:

       <Picker
          style={{height: 50,width: 100}} // <-----

          testID="basic-picker"
          selectedValue={value}
          onValueChange={(v) => setValue(v)}>
          <Item label="hello" value="key0" />
          <Item label="world" value="key1" />
        </Picker>

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...