0

I am new to React Native, I'm following a video tutorial for beginners. I'm developing on windows 10 and using React Native version 0.49.1 . In the tutorial I'm following there are two index files: index.android.js & index.ios.js. As I understand those file are untied now to index.js file, I got it from this question that was asked. Nevertheless, I still want to work with two separate index files, but I don't know how to do so - do I have to delete App.js file and index.js files? And if so, what should be the content of index.android.js & ios files? I would appreciate an explanation or a quick guide on how to do it. Thanks in advance :)

2
  • did you create your new project with react-native init or create-react-native-app command? Commented Oct 7, 2017 at 12:40
  • I used react-native init Commented Oct 7, 2017 at 12:41

1 Answer 1

0

For projects created with react-native init, an index.js file is still generated, and looks something like this initially:

import { AppRegistry } from 'react-native';
import App from './App';

AppRegistry.registerComponent('YourProjectName', () => App);

Manually adding App.ios.js and App.android.js in the same directory will allow you to include unique code for each platform, as it follows the pattern for platform-specific extensions. However, it won't be enough to have either one or the other. You need to include both otherwise the code splitting won't take effect (and will default to whatever is present in App.js).

So to answer your question, yes you need to delete App.js and replace it with android.App.js and ios.App.js. Then restart the React Native packager terminal window for your simulator or device to detect the change.

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

1 Comment

Hi, thanks for the answer, I'm going to try it out and update later :)

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.