无法在react-native中将类作为函数调用

时间:2019-11-16 04:40:30

标签: react-native expo

我目前正在使用EXPO在本机项目上工作,但是发生了一个错误,我将分享我的错误和代码,我应该在哪里更改

https://i.stack.imgur.com/kCMGk.png

App.js

import React from 'react';
import MovieList from './components/list';
import  Detail from './components/detail';


import { createAppContainer } from 'react-navigation';
import { createStackNavigator } from 'react-navigation-stack';

const AppNavigator = createStackNavigator({
  MovieList: {screen: MovieList},
  Detail: {screen: Detail},

})

const App = createAppContainer(AppNavigator);

export default App();

detail.js

import React from 'react';
import MovieList from './components/list';
import  Detail from './components/detail';


import { createAppContainer } from 'react-navigation';
import { createStackNavigator } from 'react-navigation-stack';

const AppNavigator = createStackNavigator({
  MovieList: {screen: MovieList},
  Detail: {screen: Detail},

})

const App = createAppContainer(AppNavigator);

export default App();

1 个答案:

答案 0 :(得分:0)

您已经在两个文件(即 App.js details.js )中编写了相同的内容。
通常,在react-native中,我们在一个文件中定义所有屏幕,类似于您在App.js文件中所做的操作,然后对于在App.js中定义的所有屏幕,您都必须为分别对 MovieList Detail 屏幕。

您的MovieList和Details屏幕应该看起来像这样。...

import React, { Component } from "react";
import { View } from "react-native";

export default class MovieList extends Component {
  constructor(props) {
    super(props);
    this.state = {

    };
  }

  render() {
    return (
      <View style={{ flex: 1, backgroundColor: 'green' }}>
        <Text> Hello world </Text>
      </View>
    );
  }
}