Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use index.js instead of (index.ios.js, index.android.js) in React Native for cross-platform app?

Thanks for the answers from now,

I am a newbie in React Native, I want to make a cross-platform app so I created index.js:

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

class ReactApp extends Component {

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

module.exports = ReactApp;

Then I imported index.js from both index.ios.js and index.android.js like this:

import { AppRegistry } from 'react-native';
import ReactApp from './index';

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

I think after this it should work but I get this error:

enter image description here

like image 720
davut dev Avatar asked Jun 28 '17 13:06

davut dev


Video Answer


1 Answers

After React v0.49, you don't need index.ios.js and index.android.js. You only need the index.js:

import {AppRegistry} from 'react-native';
import App from './app/App';

AppRegistry.registerComponent('appMobile', () => App);

(replace appMobile with the name of your app)

Source: (https://github.com/facebook/react-native/releases/tag/v0.49.0)

New projects have a single entry-point (index.js) from now on

like image 158
Floris M Avatar answered Oct 13 '22 17:10

Floris M