简体   繁体   中英

Unable to import react native custom module

I am using react-native ES6. No compile time errors and no runtime errors. I tried to import a Main module, but I don't have any errors. Here is the below code for Main.js file:

'use-strict';
import React, {Component} from 'react';
import {View, Text, StyleSheet} from 'react-native';

class Main extends Component {
  render() {
    return (
      <View style={{justifyContent:'flex-start', marginTop: 120}}>
      <Text style={{fontSize:20}}> Testing the router</Text>
      <Text> Testing the router</Text>
      </View>
    );
  }
}

module.exports = Main;

Here is my first project file. I am trying to import Main.js file.

'use-strict';
import React, { Component } from 'react';
import {
  AppRegistry,
  StyleSheet,
  Text,
  View,
  NavigatorIOS
} from 'react-native';
import Main from './Main.js';

export default class FirstProject extends Component {
  render() {
    return (
      <NavigatorIOS
        initialRoute={{
          title: 'App Title',
          component: Main
        }} />
    );
  }
}

AppRegistry.registerComponent('FirstProject', () => FirstProject);

Node.js-style single-value exports don't work. There, you export single value instead of object: module.exports = Main

Change it to module.exports.Main

a better syntax is to use export default Main

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM