ZeroChow
ZeroChow

Reputation: 442

How do I modify android & iOS project to make the entry file as a common js file in react native?

As mentioned in the title, I wanna change the android entry file(index.android.js) and iOS entry file(index.ios.js) to a common js file named index.js, How do I modify in project?

Upvotes: 2

Views: 426

Answers (1)

Jickson
Jickson

Reputation: 5193

We cannot achieve that currently. We will get the following error if we try to do so.

enter image description here

One way to simulate single entry point is by creating a container component having a single entry point your application like below

Application.js

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

class Application extends Component {

    render() {
        return (
            <View><Text>Hello world</Text></View>
        );
    }
}

module.exports = Application;

and copy paste the same contents in index.ios.js and index.android.js

import {
  AppRegistry,
} from 'react-native';

import Application from './Application';
AppRegistry.registerComponent('YourAppName', () => Application);

Upvotes: 3

Related Questions