Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React Native project do not have index.ios.js or index.android.js

Hi I am newbie for React Native. I followed below link to build my first project but found there is no index.ios.js or index.android.js for me to edit:

https://facebook.github.io/react-native/docs/getting-started.html

Only App.js is created, May I know how can I edit for ios and android separately? Thanks!

like image 214
Lee f051780 Avatar asked Sep 27 '17 18:09

Lee f051780


People also ask

Is there an index JS for react native?

index.js is the starting point for React Native applications, and it is always required.

What is App JS and index JS in react native?

“App. js” is the starting point of your Application that you are bootstrapping in “index. js.” As you can see, it is just a regular React component. The only difference is that you are using predefined components from “react-native.” We will start by creating a folder to hold our components.


2 Answers

For the latest version of React native(0.49.3), it seems that the "index.android.js" and "index.ios.js" separate entry routes are no longer supported. The developer documentation suggests we use the App.js and only change parts of platform specific code by importing {Platform} from react-native package if needed.

Developer documentation

like image 99
Arnab Kar Avatar answered Oct 02 '22 18:10

Arnab Kar


Firstly make sure that you are done with the downloads of:

  • Java Sdk
  • Android Studio
  • Xcode (in case of OSX)
  • HomeBrew (in case of OSX to install node)
  • Node/NPM (Node runs Javascript outside the browser. NPM is used for installing and managing Dependencies. Node and NPM come together)

Those are some essential installs that you will need in your Project

For windows/OSX you need to run the following commands in your command prompt/command line:

This is the important part for running a react native project:

  • npm install -g react-native-cli

Then you can use this cli to start a new project like this:

  • react-native init projectname

after following these steps you can get the index.android.js file and the index.ios.js file where you can code/ edit for ios/android seperately

App.js or any other file can be created by us while index.android.js and index.ios.js file comes by default

But now we have index.js file instead of index.android.js and index.ios.js and an App.js file, so you can write your codes in App.js and register the file in index.js to make it work on both ios and android

so your app registers only once that is in index.js earlier we need to copy paste the same registering code in both index.ios.js and index.android.js to make it work on android and ios that was like duplication of the same code so they must have deprecated that

like image 38
Adarsh Sreeram Avatar answered Oct 02 '22 19:10

Adarsh Sreeram