【问题标题】:React-Native type is invalid -- expected a stringReact-Native 类型无效——需要一个字符串
【发布时间】:2020-04-22 01:24:35
【问题描述】:

我从 react native 开始,我发现下一个错误,我有点迷失方向。

我从 App.js 导入组件 Home.js,但出现以下错误:

###错误#################

警告:React.createElement:类型无效——需要一个字符串(对于内置组件)或一个类/函数(对于复合组件) 但是得到:%s.%s%s,未定义,您可能忘记从定义组件的文件中导出组件,或者您可能混淆了默认导入和命名导入。

#### App.js #############

import React, { Component } from 'react';
import { StyleSheet, Text, View, TextInput, TouchableOpacity } from 'react-native';

import { Home } from './componentes/Home';

export default class App extends Component {

  render(){
    return(
      <View>
        <Home />
      </View>
  );
}

### ./componentes/Home.js ###########

import React, { Component } from 'react';
import { StyleSheet, Text, View, TextInput, TouchableOpacity } from 'react-native';

export default class Home extends Component{
    render() {
      return (
        <Text>Home</Text>
      );
    }
  }

【问题讨论】:

  • 这里是英文的 StackOverflow,请在这里只用英文提问。
  • 他的问题是有效的,只是他用任何语言发表过,也许是西班牙语。

标签: react-native mobile


【解决方案1】:

只需在您的App.js 中更改您将 Home 导入到的方式,

import  Home  from './componentes/Home';

而不是下面的那个

import { Home } from './componentes/Home';

希望对你有帮助,欢迎提问

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-05-27
    • 1970-01-01
    • 2018-09-14
    • 1970-01-01
    • 2018-01-18
    • 2017-08-06
    • 2023-01-31
    • 2020-05-10
    相关资源
    最近更新 更多