我有一个非常简单的react native应用程序,目前只有两个屏幕,一个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
我知道这是一个非常常见的错误,但我无法找到解决方案。有人可以帮我吗?
解决此问题:
尝试将您的Login组件设置为适当的React组件,如下所示: