7

The declaration of AppRegistry.registerComponent is as follows:

static registerComponent(appKey, componentProvider, section?) 

The appKey variable is generated to be the same as the project name given in react-native init projname. But what is this value used for? If I change it to something else, the app throws an exception. How would I change this value to something else?

2 Answers2

14

When you call AppRegistry.registerComponent you're creating the bridge between javascript land and native land.

So if registering your component looks like this...

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

Then your AppDelegate.m file will look something like this...

RCTRootView *rootView = [[RCTRootView alloc] initWithBundleURL:jsCodeLocation
                                                 moduleName:@"App"
                                                 initialProperties:nil
                                                 launchOptions:launchOptions];

The important part to note is this... moduleName:@"App", where we're using the appKey and creating a RCTRootView mapped to the string "App" (e.g. your appKey)

These two strings should agree so that the RCTRootView knows how to map back to your app's javascript logic.

Chris Geirman
  • 9,474
  • 5
  • 37
  • 70
-5

Bit of a duplicate question: Renaming a React Native project?

Change the name in:

package.json

then run:

react-native upgrade

and change:

AppRegistry.registerComponent('projname', () => projname);

to:

AppRegistry.registerComponent('newName', () => newName);

If changing the project name leaves the appKey value as the old project value then I would be surprised.

John Denver
  • 362
  • 1
  • 12