41

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!

4
  • 1
    which command you are firing for creating react native project? Commented Sep 28, 2017 at 4:05
  • 1
    create-react-native-app AwesomeProject Commented Sep 28, 2017 at 6:27
  • 1
    use this command react-native init YourProjectName Commented Sep 28, 2017 at 6:37
  • but use this command I seems cannot use expo for app preview? Commented Sep 28, 2017 at 6:49

5 Answers 5

53

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

Sign up to request clarification or add additional context in comments.

2 Comments

raywenderlich.com/165140/… Was following the above article which was written very recently and was quite confused. Thanks for the clarification.
Thank you for sharing this info! Because of this comment, I was able to search for additional information which helped as well. This other thread was useful: stackoverflow.com/questions/46510221/…
37

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

8 Comments

thanks for the reply, may I know if this method can use expo for preview the application? if yes, how to implement expo to the project? thanks
yes the same applies for expo after you finish all the above steps install expo xde then create a new project in expo xde open the project in an editor and you can write codes in App.js and run it on devices via expo
may i know react-native init project name and create new project in expo are the same folder?
you need to do either ways like if u are trying to develop an app via expo then u should create an expo project
I have done all the above mentioned steps, still I don't find them in my project. Also, my project runs perfectly in Android Emulator. Is both the files index.android.js and index.ios.js are removed from react-native?
|
1

According to this article, even in React Native 0.60 those platform specific file extensions are still supported.

https://facebook.github.io/react-native/docs/platform-specific-code#platform-specific-extensions

Comments

1

Henceforth and with coming versions of React Native development platform, the index.ios.js and index.android.js files are no longer available for development purposes. There is now a single file that one can use to carry out all development activities- the App.js in relation with the index.js file (just like the normal React.js) way of doing things.

STEPS ON MAC OS

  1. Ensure that you set all development packages using the MAC OS terminal

  2. Download and install the latest Node.js package

  3. Run npm --version to confirm the installation of the latest Node.js version

  4. Still, on your terminal, install HomeBrew using

    /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
    
  5. Then install watchman usingbrew install watchman

  6. Finally, install React-Native using

    npm install -g react-native-cli
    

Then you can start building your react native app using

react-native init appName

Editing the App.js and the index.js files are what you'll do in most cases when developing. You might as well download some other dependencies as you see fit.

Comments

1

You can manually create a javascript file and name it index.android.js or index.ios.js. The commands written in these files can be the same as of index.js file or even be platform-specific.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.