如何在React Native中使用index.js代替(index.ios.js,index.android.js)进行跨平台应用?

如何在React Native中使用index.js代替(index.ios.js,index.android.js)进行跨平台应用?

问题描述:

感谢您从现在开始的答案,

Thanks for the answers from now,

我是 React Native 的新手,我想创建一个跨平台的应用程序我创建了index.js:

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;

然后我从index.ios.js和index.android.js这样导入了index.js :

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:

React v0之后.49,你不需要 index.ios.js index.android.js 。您只需要 index.js

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);

(用你的名字替换 appMobile app)

(replace appMobile with the name of your app)

资料来源:( https://github.com/facebook/react-native/releases/tag/v0.49.0


从现在开始,新项目只有一个入口点(index.js)

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