react-native app.js index.js

后端 未结 1 1962
耶瑟儿~
耶瑟儿~ 2021-02-13 09:28

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 crea

相关标签:
1条回答
  • 2021-02-13 10:07

    React Native: (react-native init)

    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.

    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.

    Bottom Line

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

    Expo: (create-react-native-app)

    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.

    Bottom Line

    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.

    0 讨论(0)
提交回复
热议问题