Javascript React本机-不变冲突:元素类型无效:应为字符串,但得到:未定义

Javascript React本机-不变冲突:元素类型无效:应为字符串,但得到:未定义,javascript,react-native,undefined,invariants,Javascript,React Native,Undefined,Invariants,所以当我使用这段代码时,一切都很好: import*as React from'React'; 从“react native”导入{按钮、图像、视图、可触摸不透明度、样式表、可触摸无反馈、键盘避免查看、SimpleImation、文本、文本输入}; 从“世博会图像采集器”导入*作为图像采集器; 从“expo常量”导入常量; 从“expo Permissions”导入*作为权限; 从“@expo/vector icons”导入{Ionicons}; 从“./button”导入FlatButton

所以当我使用这段代码时,一切都很好:

import*as React from'React';
从“react native”导入{按钮、图像、视图、可触摸不透明度、样式表、可触摸无反馈、键盘避免查看、SimpleImation、文本、文本输入};
从“世博会图像采集器”导入*作为图像采集器;
从“expo常量”导入常量;
从“expo Permissions”导入*作为权限;
从“@expo/vector icons”导入{Ionicons};
从“./button”导入FlatButton;
常量第三颜色='红色';
const secColor='蓝色';
常量mainColor='绿色';
导出默认类ImagePickerExample扩展React.Component{
状态={
图像:空,
};
返回(
{图像&&
}
);
…
将图像状态更改为“”(空字符串)而不是null或处理图像uri的null条件

import * as React from 'react';
import { Button, Image, View, TouchableOpacity, StyleSheet, TouchableWithoutFeedback, KeyboardAvoidingView, SimpleAnimation, Text, TextInput} from 'react-native';
import * as ImagePicker from 'expo-image-picker';
import Constants from 'expo-constants';
import * as Permissions from 'expo-permissions';
import { Ionicons } from '@expo/vector-icons';
import FlatButton from './button';

const thirdColor = 'red'; 
const secColor = 'blue'; 
const mainColor = 'green'; 

export default class ImagePickerExample extends React.Component {

  state = {
    image: "",
  };

  return (
  <View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
    <Button
      title="Pick an image from camera roll"
      onPress={this._pickImage}
    />
    {image &&
      <Image source={{ uri: image }} style={{ width: 200, height: 200 }} />}
  </View>
);
import*as React from'React';
从“react native”导入{按钮、图像、视图、可触摸不透明度、样式表、可触摸无反馈、键盘避免查看、SimpleImation、文本、文本输入};
从“世博会图像采集器”导入*作为图像采集器;
从“expo常量”导入常量;
从“expo Permissions”导入*作为权限;
从“@expo/vector icons”导入{Ionicons};
从“./button”导入FlatButton;
常量第三颜色='红色';
const secColor='蓝色';
常量mainColor='绿色';
导出默认类ImagePickerExample扩展React.Component{
状态={
图像:“”,
};
返回(
{图像&&
}
);
将图像状态更改为“”(空字符串)而不是null或处理图像uri的null条件

import * as React from 'react';
import { Button, Image, View, TouchableOpacity, StyleSheet, TouchableWithoutFeedback, KeyboardAvoidingView, SimpleAnimation, Text, TextInput} from 'react-native';
import * as ImagePicker from 'expo-image-picker';
import Constants from 'expo-constants';
import * as Permissions from 'expo-permissions';
import { Ionicons } from '@expo/vector-icons';
import FlatButton from './button';

const thirdColor = 'red'; 
const secColor = 'blue'; 
const mainColor = 'green'; 

export default class ImagePickerExample extends React.Component {

  state = {
    image: "",
  };

  return (
  <View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
    <Button
      title="Pick an image from camera roll"
      onPress={this._pickImage}
    />
    {image &&
      <Image source={{ uri: image }} style={{ width: 200, height: 200 }} />}
  </View>
);
import*as React from'React';
从“react native”导入{按钮、图像、视图、可触摸不透明度、样式表、可触摸无反馈、键盘避免查看、SimpleImation、文本、文本输入};
从“世博会图像采集器”导入*作为图像采集器;
从“expo常量”导入常量;
从“expo Permissions”导入*作为权限;
从“@expo/vector icons”导入{Ionicons};
从“./button”导入FlatButton;
常量第三颜色='红色';
const secColor='蓝色';
常量mainColor='绿色';
导出默认类ImagePickerExample扩展React.Component{
状态={
图像:“”,
};
返回(
{图像&&
}
);
  • 检查是否已导入您使用的所有方法
  • 使用this.state.image而不是image
  • 重新运行或重新加载
  • 检查是否已导入您使用的所有方法
  • 使用this.state.image而不是image
  • 重新运行或重新加载

  • 因此,问题在于我的render()中的
    标记。这是因为不知何故,此导入出错。因此,我执行了以下操作,解决了我的问题:

  • npm卸载本地简单动画
  • npm安装react原生简单动画
  • 导入代码后,请使用:
    import{SimpleAnimation}from'react native-simple animations';
    不要忘记
    {}

  • 因此,问题在于我的render()中的
    标记。这是因为不知何故,此导入出错。因此,我执行了以下操作,解决了我的问题:

  • npm卸载本地简单动画
  • npm安装react原生简单动画
  • 导入代码后,请使用:
    import{SimpleAnimation}from'react native-simple animations';
    不要忘记
    {}

  • 感谢您的快速回复。我测试了它,但它不起作用。我收到了相同的错误消息,我在底部的帖子中添加了它们。但我认为这些方法不会有问题,因为第一个代码有效,第二个代码无效,我唯一更改的是render()方法所以我才发现:只要我对所有的
    进行注释,一切都会重新开始。为什么
    会有问题?谢谢你的快速回复。我测试了它,但它不起作用。我收到了相同的错误信息,我把它们放在了底部的帖子中。但是我认为这些方法不会有问题,因为第一个代码是有效的第二个不是,我唯一更改的是render()方法所以我才发现:只要我对所有的
    进行注释,一切都会恢复正常。为什么
    有问题?你导入了所有你使用的组件吗?@TwinklePatel是的,我导入了所有你使用的组件吗?@TwinklePatel是的,所以我尝试了,但仍然是同样的错误。我用第一个代码替换了我的整个渲染又一次,它成功了。但是,当我重新更改渲染方法的内容时,我又出现了错误,因为我刚刚发现:只要我对所有
    进行注释,一切都会重新工作。为什么
    会出问题呢?所以我尝试了,但仍然是相同的错误。我再次用第一个代码替换了整个渲染,它成功了。但是很快n当我重新更改渲染方法的内容时,我再次遇到了错误,因为我刚刚发现:只要我对所有
    进行注释,所有内容都会重新工作。为什么
    会出现问题?