英文:
React-Native type is invalid -- expected a string
问题
I'm starting with react native and I find the next mistake, I'm a little disoriented.
From App.js I import the component Home.js, but I get the following error:
### ERROR #################
Warning: React.createElement: type is invalid -- expected a string (for built-in components) or a class/function (for composite components)
but got: %s.%s%s, undefined, You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.
#### 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(
);
}
### ./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 (
);
}
}
英文:
I'm starting with react native and I find the next mistake, I'm a little disoriented.
From App.js I import the component Home.js, but I get the following error:
### ERROR #################
Warning: React.createElement: type is invalid -- expected a string (for built-in components) or a class/function (for composite components)
but got: %s.%s%s, undefined, You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.
#### 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>
);
}
}
答案1
得分: 1
只需在你的 App.js
中修改导入 Home 组件的方式,从:
import { Home } from './componentes/Home';
改为:
import Home from './componentes/Home';
希望能帮助你,有疑问请随时提问。
英文:
Just in your App.js
change your way of importing Home to ,
import Home from './componentes/Home';
AND NOT THE ONE BELOW
import { Home } from './componentes/Home';
hope it helps , feel free for doubts
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论