2017-11-08 00:34:50 +00:00
---
id: appregistry
title: AppRegistry
layout: docs
category: APIs
permalink: docs/appregistry.html
next: appstate
previous: animated
---
< div class = "banner-crna-ejected" >
< h3 > Project with Native Code Required< / h3 >
< p >
2017-11-20 21:07:10 +00:00
This API only works in projects made with < code > react-native init< / code > or in those made with Create React Native App which have since ejected. For more information about ejecting, please see the < a href = "https://github.com/react-community/create-react-native-app/blob/master/EJECTING.md" target = "_blank" > guide< / a > on the Create React Native App repository.
2017-11-08 00:34:50 +00:00
< / p >
< / div >
2017-11-20 21:07:10 +00:00
`AppRegistry` is the JavaScript entry point to running all React Native apps. App root components should register themselves with `AppRegistry.registerComponent()` , then the native system can load the bundle for the app and then actually run the app when it's ready by invoking `AppRegistry.runApplication()` .
2017-11-08 00:34:50 +00:00
2017-11-20 21:07:10 +00:00
To "stop" an application when a view should be destroyed, call `AppRegistry.unmountApplicationComponentAtRootTag()` with the tag that was passed into `runApplication()` . These should always be used as a pair.
`AppRegistry` should be `require` d early in the `require` sequence to make sure the JavaScript execution environment is set up before other modules are `require` d.
2017-11-08 00:34:50 +00:00
### Methods
2017-11-20 21:07:10 +00:00
- [`registerComponent` ](docs/appregistry.html#registercomponent )
- [`runApplication` ](docs/appregistry.html#runapplication )
- [`unmountApplicationComponentAtRootTag` ](docs/appregistry.html#unmountapplicationcomponentatroottag )
- [`registerHeadlessTask` ](docs/appregistry.html#registerheadlesstask )
- [`startHeadlessTask` ](docs/appregistry.html#startheadlesstask )
2017-11-08 00:34:50 +00:00
- [`setWrapperComponentProvider` ](docs/appregistry.html#setwrappercomponentprovider )
- [`registerConfig` ](docs/appregistry.html#registerconfig )
- [`registerRunnable` ](docs/appregistry.html#registerrunnable )
- [`registerSection` ](docs/appregistry.html#registersection )
- [`getAppKeys` ](docs/appregistry.html#getappkeys )
- [`getSectionKeys` ](docs/appregistry.html#getsectionkeys )
- [`getSections` ](docs/appregistry.html#getsections )
- [`getRunnable` ](docs/appregistry.html#getrunnable )
- [`getRegistry` ](docs/appregistry.html#getregistry )
- [`setComponentProviderInstrumentationHook` ](docs/appregistry.html#setcomponentproviderinstrumentationhook )
---
# Reference
## Methods
2017-11-20 21:07:10 +00:00
### `registerComponent()`
2017-11-08 00:34:50 +00:00
```javascript
2017-11-20 21:07:10 +00:00
AppRegistry.registerComponent(appKey, componentProvider, [section])
2017-11-08 00:34:50 +00:00
```
2017-11-20 21:07:10 +00:00
Registers an app's root component.
2017-11-08 00:34:50 +00:00
2017-11-20 21:07:10 +00:00
**Parameters:**
| Name | Type | Required | Description |
| - | - | - | - |
| appKey | string | Yes | Application key. |
| componentProvider | function | Yes | A function that returns a React component or element. |
| section | boolean | No | Is this a section? |
2017-11-08 00:34:50 +00:00
---
2017-11-20 21:07:10 +00:00
### `runApplication()`
2017-11-08 00:34:50 +00:00
```javascript
2017-11-20 21:07:10 +00:00
AppRegistry.runApplication(appKey, appParameters)
2017-11-08 00:34:50 +00:00
```
2017-11-20 21:07:10 +00:00
Loads the JavaScript bundle and runs the app.
2017-11-08 00:34:50 +00:00
2017-11-20 21:07:10 +00:00
**Parameters:**
| Name | Type | Required | Description |
| - | - | - | - |
| appKey | string | Yes | Application key. |
| appParameters | any | Yes | Params. |
2017-11-08 00:34:50 +00:00
---
2017-11-20 21:07:10 +00:00
### `unmountApplicationComponentAtRootTag()`
2017-11-08 00:34:50 +00:00
```javascript
2017-11-20 21:07:10 +00:00
AppRegistry.unmountApplicationComponentAtRootTag(rootTag)
2017-11-08 00:34:50 +00:00
```
2017-11-20 21:07:10 +00:00
Stops an application when a view should be destroyed. The `rootTag` should match the tag that was passed into `runApplication()` . These should always be used as a pair.
2017-11-08 00:34:50 +00:00
2017-11-20 21:07:10 +00:00
**Parameters:**
| Name | Type | Required | Description |
| - | - | - | - |
| rootTag | number | Yes | React tag. |
2017-11-08 00:34:50 +00:00
---
2017-11-20 21:07:10 +00:00
### `registerHeadlessTask()`
2017-11-08 00:34:50 +00:00
```javascript
2017-11-20 21:07:10 +00:00
AppRegistry.registerHeadlessTask(taskKey, task)
2017-11-08 00:34:50 +00:00
```
2017-11-20 21:07:10 +00:00
Register a headless task. A headless task is a bit of code that runs without a UI.
**Parameters:**
| Name | Type | Required | Description |
| - | - | - | - |
| taskKey | string | No | The key associated with this task. |
| task | function | No | A promise returning function that takes some data passed from the native side as the only argument; when the promise is resolved or rejected the native side is notified of this event and it may decide to destroy the JS context. |
2017-11-08 00:34:50 +00:00
---
2017-11-20 21:07:10 +00:00
### `startHeadlessTask()`
2017-11-08 00:34:50 +00:00
```javascript
2017-11-20 21:07:10 +00:00
AppRegistry.startHeadlessTask(taskId, taskKey, data)
2017-11-08 00:34:50 +00:00
```
2017-11-20 21:07:10 +00:00
Only called from native code. Starts a headless task.
**Parameters:**
| Name | Type | Required | Description |
| - | - | - | - |
| taskId | number | No | The native id for this task instance to keep track of its execution. |
| taskKey | string | No | The key for the task to start. |
| data | any | No | The data to pass to the task. |
2017-11-08 00:34:50 +00:00
---
2017-11-20 21:07:10 +00:00
### `setWrapperComponentProvider()`
2017-11-08 00:34:50 +00:00
```javascript
2017-11-20 21:07:10 +00:00
AppRegistry.setWrapperComponentProvider(provider)
2017-11-08 00:34:50 +00:00
```
---
2017-11-20 21:07:10 +00:00
### `registerConfig()`
2017-11-08 00:34:50 +00:00
```javascript
2017-11-20 21:07:10 +00:00
AppRegistry.registerConfig(config)
2017-11-08 00:34:50 +00:00
```
---
2017-11-20 21:07:10 +00:00
### `registerRunnable()`
2017-11-08 00:34:50 +00:00
```javascript
2017-11-20 21:07:10 +00:00
AppRegistry.registerRunnable(appKey, run)
2017-11-08 00:34:50 +00:00
```
---
2017-11-20 21:07:10 +00:00
### `registerSection()`
2017-11-08 00:34:50 +00:00
```javascript
2017-11-20 21:07:10 +00:00
AppRegistry.registerSection(appKey, component)
2017-11-08 00:34:50 +00:00
```
---
2017-11-20 21:07:10 +00:00
### `getAppKeys()`
2017-11-08 00:34:50 +00:00
```javascript
2017-11-20 21:07:10 +00:00
AppRegistry.getAppKeys()
2017-11-08 00:34:50 +00:00
```
---
2017-11-20 21:07:10 +00:00
### `getSectionKeys()`
2017-11-08 00:34:50 +00:00
```javascript
2017-11-20 21:07:10 +00:00
AppRegistry.getSectionKeys()
2017-11-08 00:34:50 +00:00
```
---
2017-11-20 21:07:10 +00:00
### `getSections()`
2017-11-08 00:34:50 +00:00
```javascript
2017-11-20 21:07:10 +00:00
AppRegistry.getSections()
2017-11-08 00:34:50 +00:00
```
---
2017-11-20 21:07:10 +00:00
### `getRunnable()`
2017-11-08 00:34:50 +00:00
```javascript
2017-11-20 21:07:10 +00:00
AppRegistry.getRunnable(appKey)
2017-11-08 00:34:50 +00:00
```
---
2017-11-20 21:07:10 +00:00
### `getRegistry()`
2017-11-08 00:34:50 +00:00
```javascript
2017-11-20 21:07:10 +00:00
AppRegistry.getRegistry()
2017-11-08 00:34:50 +00:00
```
---
2017-11-20 21:07:10 +00:00
### `setComponentProviderInstrumentationHook()`
2017-11-08 00:34:50 +00:00
```javascript
2017-11-20 21:07:10 +00:00
AppRegistry.setComponentProviderInstrumentationHook(hook)
2017-11-08 00:34:50 +00:00
```