如何解决React Native中的AppRegistry.registerComponent错误

时间:2017-05-04 11:16:44

标签: android ios facebook react-native

刚开始探索React Native但不幸的是,我遇到了这个错误

App(...):必须返回有效的React元素(或null)。你可以  已返回undefined,数组或其他一些无效对象

我已尝试检查并参考其他问题,但无法弄明白。请检查附加的屏幕截图 - Simulator Screen Shot 这是我的index.ios看起来像

的方式
import React from 'react';
import { AppRegistry, View } from 'react-native';
import Header from './src/components/Header';
import AlbumList from './src/components/AlbumList';

//Create a Component
const App = () => {
   <View>
     <Header headerText={'Albums'} />;
     <AlbumList />
   </View>;
};

//Render it to the device
AppRegistry.registerComponent('albums', () => App);

任何建议都会非常有帮助

谢谢。

1 个答案:

答案 0 :(得分:1)

尝试在App函数中添加一个回复:

const App = () => {
  return (
   <View>
     <Header headerText={'Albums'} />;
     <AlbumList />
   </View>
  );
};