react-native - 反应本机错误 - 期望一个字符串或一个类但得到对象
问题描述
我是反应原生的新手。我试图编写从教程中找到的简单程序,以熟悉 react-native 环境。我研究了 stackoverflow 本身的相同错误,但找不到任何有用的解决方案,这就是我再次写信的原因。
我指的是以下教程
以下是我使用的代码。创建了一个名为 EmojiDict.js 的新类
import React, { Component } from 'react'
import { View, Text, StyleSheet } from 'react-native'
class EmojiDict extends Component {
state = {
'': ' Smiley',
'': ' Rocket',
'⚛️': '⚛️ Atom Symbol'
};
render() {
return (
<View style={styles.container} >
<Text>this.state[''] </Text>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#F5FCFF'
},
instructions: {
textAlign: 'center',
color: '#333333',
marginBottom: 5
}
});
然后修改 App.js 类如下:
import React, { Component } from 'react';
import { Platform, StyleSheet, Text, View } from 'react-native';
import EmojiDict from './src/components/EmojiDict';
export default class App extends Component {
render() {
return <EmojiDict />;
}
}
我尝试了各种示例,但在 App.js 类被修改时没有任何效果。由于此错误,我无法继续前进。
解决方案
看起来你忘记导出EmojiDict
组件了
代替class EmojiDict extends Component {
尝试
export default class EmojiDict extends Component {
可以解决这个问题
推荐阅读
- json - 如何通过 Json 主体 Powershell 传递变量
- python - 计算日志文件的最大并发唯一用户数
- android - SearchView 在滚动之前不会更新 RecyclerView
- python - 带 Gif 图像的 ImDecode
- f# - F# SQLProvider 错误 FS0039:类型“dataContext”未定义字段、构造函数或成员“test”。在演示中
- node.js - 提取 JWT 时请求未定义
- scala - Scala中是否有一些基于条件的类型?
- amazon-web-services - 在 eks 中为服务创建服务端点
- c# - 带有附加参数的 WebApi POST
- git - 如何推送没有文件夹 .gitignore 规则的文件来提供