Skip to main content

AppRegistry

AppRegistry starts your app, as on native. On the web, runApplication renders the root component into an element of the page with React DOM.

index.web.js
import { AppRegistry } from 'react-native'

import App from './App'

AppRegistry.registerComponent('main', () => App)
AppRegistry.runApplication('main', { rootTag: document.getElementById('root') })

With Expo, Expo calls AppRegistry for you. With Vite, you can also render with createRoot, as Mount your app shows.

MemberOn the web
registerComponent(appKey, componentProvider)Registers the root component of an app. Returns appKey.
runApplication(appKey, { rootTag, initialProps, hydrate })Renders the root component into rootTag, a DOM element, with initialProps. With hydrate: true, it hydrates the server HTML in rootTag. A second call on the same element renders into the same React root. It throws when rootTag is missing or appKey isn't registered.
unmountApplicationComponentAtRootTag(rootTag)Unmounts the app that runApplication rendered into rootTag.
getApplication(appKey, { initialProps })For a render on a server: returns { element, getStyleElement }. See Server render. React Native doesn't have it; react-native-web does.
registerRunnable(appKey, run)Registers a function that runApplication calls with its parameters, in place of a render. getApplication throws for this key.
registerConfig(configs)Registers each { appKey, component } and each { appKey, run }. section has no effect.
getAppKeys()The key of each registered app.
setWrapperComponentProvider(provider)provider(appParameters, appKey) returns a component that wraps the root component of each app, for example a context provider.
setComponentProviderInstrumentationHook(hook)hook(componentProvider) returns the root component, in place of componentProvider().

The root component renders straight into rootTag, with no view around it. react-native-web puts two views with flex: 1 around it. Give rootTag a flex layout, as Mount your app shows, so that flex: 1 on your root view fills the page.

React Native's headless tasks, sections, and surfaces have no meaning in a browser. So registerHeadlessTask, registerCancellableHeadlessTask, startHeadlessTask, cancelHeadlessTask, registerSection, getSectionKeys, getSections, getRunnable, getRegistry, setRootViewStyleProvider, and setSurfaceProps aren't there.

Server render​

getApplication(appKey, { initialProps }) returns two things:

  • element: the root component with initialProps, wrapped as runApplication wraps it. Render it with renderToString or a stream of React DOM. Its CSS renders with it, as Server rendering shows.
  • getStyleElement(props): a <style id="react-native-stylesheet"> with the reset of the document, as react-native-web's style sheet starts: body gets no margin. Put it in <head>. Its props go to the element, for example a nonce.

In the browser, call runApplication with hydrate: true and the same initialProps.