javascript - 反应原生不会导入另一个组件
问题描述
我有一个非常简单的反应原生应用程序,它现在只有两个屏幕,一个 app.js 和一个 login.js
当我设置这个应用程序时,我想在应用程序组件中显示登录组件。
这是 app.js 组件的外观。
import React from 'react';
import { View } from 'react-native';
import Login from "login.js"
export default function App() {
return (
<View style={styles.container}>
<Login > </Login>
{/* <Text>This is a test</Text> */}
</View>
);
}
这是 login.js 的样子
import React from 'react';
import { Text, View, Input } from 'react-native';
const users = [
{
name: "Sarthak",
age: 29,
address: "BG3",
}
]
export default Login = () => {
return (
<View>
<View>
<Text>{users[0].name}</Text>
<Input></Input>
</View>
<View>
<Text>Password</Text>
<Input></Input>
</View>
</View>
)
}
我得到的错误是这个
Invariant Violation: Element type is invalid: expected a string( for built-in components) or a class/function (for composite components) but got: object. You likely forgot to export your component from the file it's defined in
我知道这是一个很常见的错误,但我无法找到解决方案。有人可以帮我吗?
解决方案
解决这个问题:
export default const Login = () => {
推荐阅读
- javascript - 如何正确输出 json 作为对象
- flutter - 必须是未来的日期:“TZDateTime”的实例
- regex - 如何使用 grafana 对来自 elasticsearch 的唯一值进行分组
- c++ - 如何通过编译标志包含头文件?
- reactjs - 有什么方法可以从反应组件点击事件重定向.net核心控制器方法吗?
- apache-flink - 两种时间连接方式,首选哪一种
- node.js - 如何使用与 webpack 捆绑的 node.js Web 应用程序获取在 OS 上运行的进程列表
- symfony - API 平台 - 有条件的急切加载
- python - 在缺少第一个值和最后一个值的情况下用熊猫插入两个方向?
- c# - 如何从 C# 应用程序将过程返回到保存点/回滚?