[英]Component Exception Invalid type
I started to learn React-Native a day ago and couldn't resolve my 'Element type is invalid: expected a string' problem.我一天前开始学习 React-Native 并且无法解决我的“元素类型无效:预期为字符串”问题。 I researched it and couldn't find a solution for my fit.
我对其进行了研究,但找不到适合我的解决方案。 Here is my very simple project:
这是我非常简单的项目:
//importing
import React from 'react';
import {Text, AppRegistry} from 'react-native';
import Header from './src/components/Header';
//own-typed components
const App = () => (
<Header/>
);
//rendering
AppRegistry.registerComponent('ORNEKPROJE', () => App);
And here is my Header.js file:这是我的 Header.js 文件:
import React from 'react';
import {Text} from 'react-native';
const Header = () => {
return <Text>Anasayfa</Text>;
};
export default Header;
Thanks for the help!谢谢您的帮助!
Try to make App
component a class component and extend it with React.Component
.尝试使
App
组件成为 class 组件并使用React.Component
扩展它。 Like this:-像这样:-
import React from 'react'
import Header from './src/components/Header';
import {AppRegistry} from 'react-native';
class App extends React.Component {
render(){
return <Header/>
}
}
AppRegistry.registerComponent('ORNEKPROJE', () => App)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.