react native不会导入其他组件

问题描述 投票:0回答:2

我有一个非常简单的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

我知道这是一个非常常见的错误,但我无法找到解决方案。有人可以帮我吗?

javascript reactjs react-native react-native-android
2个回答
1
投票

解决此问题:


-1
投票

尝试将您的Login组件设置为适当的React组件,如下所示:

© www.soinside.com 2019 - 2024. All rights reserved.