React Native之编译提示Only one default export allowed per module.

1 问题

部分代码如下

class HomeScreen extends React.Component {
  render() {
    return (
      <View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
        <Text>Home Screen</Text>
      </View>
    );
  }
}

export default createStackNavigator({
  Home: {
    screen: HomeScreen
  },
});

export default class App extends React.Component {
  render() {
    return <RootStack/>;
  }
}

2 解决办法

export default 声明只能有一个,改成如下即可

import React from 'react';
import { View, Text } from 'react-native';
import { createStackNavigator } from 'react-navigation';

class HomeScreen extends React.Component {
  render() {
    return (
      <View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
        <Text>Home Screen</Text>
      </View>
    );
  }
}

const RootStack = createStackNavigator({
    Home : {
        screen : HomeScreen
    },
});

export default class App extends React.Component {
  render() {
    return <RootStack/>;
  }
}
(0)

相关推荐