react-native app.js index.js [英] react-native app.js index.js

查看:86
本文介绍了react-native app.js index.js的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是使用 React-native 开发应用程序的新手.在使用命令 react-native init appname 创建项目时,还会在项目文件夹中创建 index.js 文件.今天,我了解到有比安装 android 模拟器更好的方法来测试 React-native 项目,那就是 Expo.要创建博览会项目,我需要使用 create-react-native-app appname 命令创建 react-native 项目.但是,使用这种方式创建项目时不会创建 index.js 文件.即使我手动创建了 index.js 文件,它也无法正常工作.

I am new to application development with React-native. While creating project with the command react-native init appname the index.js file is also created inside the project folder. Today, I have learned that there is a better way than installing android emulator to test react-native projects which is Expo. To create expo projects I need to create react-native project with create-react-native-app appname command. However, the index.js file is not created while creating project with this way. Even though, I manually created the index.js file, it does not work as it should.

还有一个问题:App.jsindex.js 的目的是什么?

One more question: What is aim of App.js and index.js?

推荐答案

React Native: (react-native init)

一点点历史.在 React Native 的早期版本中,iOS 和 Android 需要单独的 index.js 文件.App.js 旨在包含您的应用的顶级跨平台代码.然后 index.ios.jsindex.android.js 将从 App.js 导入跨平台代码并将其注册/链接到底层原生模块.这允许您将顶级跨平台代码放置在一个文件中,同时将顶级平台特定代码放置在其他文件中.index.*.js 文件是将 Javascript 连接到原生 Android 或 iOS 代码的连接器.

A little bit of history. In earlier versions of React Native, separate index.js files were required for iOS and Android. App.js was meant to contain the top level cross platform code for your app. Then index.ios.js and index.android.js would import the cross platform code from App.js and register/link it with the underlying native modules. That allowed you to place top-level cross platform code in one file while placing top-level platform specific code in other files. The index.*.js files were the connectors that wired up the Javascript to native Android or iOS code.

随着 React Native 的发展以移除特定于平台的索引文件,他们保留了在 App.js 中拥有顶级 Javascript 并使用 index.js 的范例将该代码连接到本机模块.

As React Native evolved to remove the platform specific index files, they kept the paradigm of having the top-level Javascript in App.js and using index.js to wire that code to the native modules.

底线

实际上,不要碰index.js.在 App.js 中进行顶级修改.

As a practical matter, don't touch index.js. Make your top-level modifications in App.js.

博览会:(create-react-native-app)

Expo 的运作方式与基准 React Native 略有不同.您会注意到 Expo 项目不包含 iosandroid 目录.那是因为没有与 Expo 项目相关联的本机代码.所有本机代码都包含在 Expo SDK 中.由于没有本地代码连接到您的 Javascript,您不需要 index.js 文件.

Expo operates a little differently than baseline React Native. You will notice that an Expo project does not contain the ios or android directories. That is because there is no native code associated with an Expo project. All of the native code is contained in the Expo SDK. Since there is no native code to wire up to your Javascript, you do not need an index.js file.

底线

您不应该在 Expo 项目中需要 index.js 文件.如果您的 Expo 项目不起作用,则可能还有另一个问题需要解决.

You should not need an index.js file in an Expo project. If your Expo project is not working, there is likely another problem that needs to be resolved.

这篇关于react-native app.js index.js的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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