首页 > 解决方案 > 反应原生不会导入另一个组件

问题描述

我有一个非常简单的反应原生应用程序,它现在只有两个屏幕,一个 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

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

标签: javascriptreactjsreact-nativereact-native-android

解决方案


解决这个问题:

export default const Login = () => {

推荐阅读