[fix] Server-side rendering

`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
This commit is contained in:
Nicolas Gallagher
2016-03-20 11:41:41 -07:00
parent 36ea662402
commit 9b2421cdfa
7 changed files with 57 additions and 18 deletions
+5 -5
View File
@@ -33,7 +33,7 @@ React.renderToStaticMarkup(<div />)
Rendering using the `AppRegistry`:
```
```js
// App.js
import React, { AppRegistry } from 'react-native'
@@ -64,12 +64,12 @@ rendering.
import React from 'react-native'
const AppShell = (html, style) => (
const AppShell = (html, styleElement) => (
<html>
<head>
<meta charSet="utf-8" />
<meta content="initial-scale=1,width=device-width" name="viewport" />
{style}
{styleElement}
</head>
<body>
<div id="react-app" dangerouslySetInnerHTML={{ __html: html }} />
@@ -90,8 +90,8 @@ import AppShell from './AppShell'
AppRegistry.registerComponent('App', () => App)
// prerenders the app
const { html, style } = AppRegistry.prerenderApplication('App', { initialProps })
const { html, style, styleElement } = AppRegistry.prerenderApplication('App', { initialProps })
// renders the full-page markup
const renderedApplicationHTML = React.renderToString(<AppShell html={html} style={style} />)
const renderedApplicationHTML = React.renderToStaticMarkup(<AppShell html={html} styleElement={styleElement} />)
```