`AppRegistry.prerenderApplication` now returns a style element for use in app shells. Guard use of `window` in APIs and Event plugin. Fix #107 Fix #108
2.3 KiB
AppRegistry
AppRegistry is the control point for registering, running, prerendering, and
unmounting all apps. App root components should register themselves with
AppRegistry.registerComponent. Apps can be run by invoking
AppRegistry.runApplication, and prerendered by invoking
AppRegistry.prerenderApplication (see the client and server rendering
guide for more details).
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.
Methods
(web) static prerenderApplication(appKey:string, appParameters: object)
Renders the given application to an HTML string. Use this for server-side
rendering. Return object is of type { html: string; style: string; styleElement: ReactComponent }. html is the prerendered HTML, style is the
prerendered style sheet, and styleElement is a React Component. It's
recommended that you use styleElement to render the style sheet in an app
shell.
static registerConfig(config: Array)
Registry multiple applications. AppConfig is of type { appKey: string; component: ComponentProvider; run?: Function }.
static registerComponent(appKey: string, getComponentFunc: ComponentProvider)
Register a component provider under the given appKey.
static registerRunnable(appKey: string, run: Function)
Register a custom render function for an application. The function will receive
the appParameters passed to runApplication.
static getAppKeys()
Returns all registered app keys.
static runApplication(appKey: string, appParameters?: object)
Runs the application that was registered under appKey. The appParameters
must include the rootTag into which the application is rendered, and
optionally any initialProps.
static unmountApplicationComponentAtRootTag(rootTag: HTMLElement)
To "stop" an application when a view should be destroyed, call
AppRegistry.unmountApplicationComponentAtRootTag with the tag that was passed
into runApplication
Example
AppRegistry.registerComponent('MyApp', () => AppComponent)
AppRegistry.runApplication('MyApp', {
initialProps: {},
rootTag: document.getElementById('react-root')
})