警告:React.createElement:类型无效

我正在尝试构建一个反应本机博览会应用程序并收到此错误

api.js


export const fetchMeetups = () =>

    fetch('http://localhost:3000/api/meetups')

        .then(res => res.json());

应用程序.js


import * as React from 'react';

import { Platform, StyleSheet, Text, View, ActivityIndicator } from 'react-native';

import { fetchMeetups } from './constants/api'; 


const instructions = Platform.select({

  ios: `Press Cmd+R to reload,\nCmd+D or shake for dev menu`,

  android: `Double tap R on your keyboard to reload,\nShake or press menu button for dev menu`,

});



class App extends React.Component{

  static defaultProps = {

    fetchMeetups

  }


  state = {

    loading: false,

    meetups: []


  }


  async componentDidMount(){

    this.setState({loading: true});

    const data = await this.props.fetchMeetups();

    setTimeout(() => this.setState({loading: false, meetups: data.meetups}),2000)

  }



  render(){

    if(this.state.loading){

      return(

        <ActivityIndicator size="large"/>

      )

    }

    return (

      <View style={styles.container}>

        <Text>MeetupME</Text>

      </View>

    );

  }


}


const styles = StyleSheet.create({

  container: {

    flex: 1,

    justifyContent: 'center',

    alignItems: 'center',

    backgroundColor: '#F5FCFF',

  },

  welcome: {

    fontSize: 20,

    textAlign: 'center',

    margin: 10,

  },

  instructions: {

    textAlign: 'center',

    color: '#333333',

    marginBottom: 5,

  },

});


索引.js


import { registerRootComponent } from 'expo';


import App from './App';


// registerRootComponent calls AppRegistry.registerComponent('main', () => App);

// It also ensures that whether you load the app in the Expo client or in a native build,

// the environment is set up appropriately

registerRootComponent(App);


桃花长相依
浏览 129回答 1
1回答

心有法竹

看起来像 App.js 缺少默认导出。index.js 尝试导入默认导出 (),因此您只需将以下内容添加到 App.js。例如,到文件末尾。import App from './App'export&nbsp;default&nbsp;App
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript