警告:道具类型失败:提供给`Image` 的道具`source` 无效。在反应原生

时间:2021-03-22 06:16:13

标签: javascript image react-native file-upload digital-signature

我是本机反应的新手。我创建了一个屏幕。其中我添加了数字签名。当我拖动签名时,我将其图像保存在状态中。然后我在屏幕上显示这个状态图像。但我收到这样的错误 = 警告:道具类型失败:提供给 source 的道具无效 Image。请帮忙。这是代码

const[Image1, setImage1]= useState(null);

    const Image1 = result.pathName;
    console.log("Response = "+Image1);
    setImage1({Image1: Image1})

 <Image
                source={{uri : Image1}}
                style={{
                 width: '100%',
                 height: 200,
                 resizeMode: 'contain',
                 }} />

1 个答案:

答案 0 :(得分:0)

useState 变量第一个单词必须小写

你不能使用相同的变量名, 如果您使用的是网络图片,那么您的图片组件应该是这样的,

const[image, setImage]= useState(null);
const [imagePath,setImagePath ] = useState(result.pathName);
console.log("Response = "+imagePath);
setImage(imagePath)

 <Image 
source={{uri : image}}
style={{
width: '100%',
height: 200,
resizeMode: 'contain',
 }} 
/>

否则,如果您使用本地图像,那么您的图像组件就像这样,

<Image 
source={require(image)}
style={{
width: '100%',
height: 200,
resizeMode: 'contain',
 }} 
/>
相关问题