如何在React Native中使用index.js代替(index.ios.js,index.android.js)进行跨平台应用? [英] How to use index.js instead of (index.ios.js, index.android.js) in React Native for cross-platform app?

查看:847
本文介绍了如何在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

这篇关于如何在React Native中使用index.js代替(index.ios.js,index.android.js)进行跨平台应用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆