From c46f242f6bbd5cecb9822d4417c2f0c1925846dd Mon Sep 17 00:00:00 2001 From: Nicolas Gallagher Date: Tue, 28 Jun 2016 16:37:28 -0700 Subject: [PATCH] [add] ReactDOM server API to ReactNative API --- README.md | 2 +- docs/guides/rendering.md | 18 ++++++++++-------- package.json | 5 ++--- src/index.js | 5 +++++ 4 files changed, 18 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index efb538f1..39202413 100644 --- a/README.md +++ b/README.md @@ -30,7 +30,7 @@ styles defined in JavaScript into "Atomic CSS". To install in your app: ``` -npm install --save react@0.14 react-dom@0.14 react-native-web +npm install --save react@0.15 react-native-web ``` Read the [Client and Server rendering](docs/guides/rendering.md) guide. diff --git a/docs/guides/rendering.md b/docs/guides/rendering.md index ae762421..4a5545c5 100644 --- a/docs/guides/rendering.md +++ b/docs/guides/rendering.md @@ -21,15 +21,14 @@ module.exports = { Rendering without using the `AppRegistry`: ```js -import ReactDOM from 'react-dom' -import ReactDOMServer from 'react-dom/server' +import ReactNative from 'react-native' // DOM render -ReactDOM.render(
, document.getElementById('react-app')) +ReactNative.render(
, document.getElementById('react-app')) // Server render -ReactDOMServer.renderToString(
) -ReactDOMServer.renderToStaticMarkup(
) +ReactNative.renderToString(
) +ReactNative.renderToStaticMarkup(
) ``` Rendering using the `AppRegistry`: @@ -54,7 +53,10 @@ import { AppRegistry } from 'react-native' AppRegistry.registerComponent('App', () => App) // mounts and runs the app within the `rootTag` DOM node -AppRegistry.runApplication('App', { initialProps, rootTag: document.getElementById('react-app') }) +AppRegistry.runApplication('App', { + initialProps: {}, + rootTag: document.getElementById('react-app') +}) ``` React Native for Web extends `AppRegistry` to provide support for server-side @@ -85,7 +87,7 @@ export default AppShell import App from './App' import AppShell from './AppShell' -import { AppRegistry } from 'react-native' +import ReactNative, { AppRegistry } from 'react-native' // registers the app AppRegistry.registerComponent('App', () => App) @@ -94,5 +96,5 @@ AppRegistry.registerComponent('App', () => App) const { html, style, styleElement } = AppRegistry.prerenderApplication('App', { initialProps }) // renders the full-page markup -const renderedApplicationHTML = React.renderToStaticMarkup() +const renderedApplicationHTML = ReactNative.renderToStaticMarkup() ``` diff --git a/package.json b/package.json index db94b401..5b605094 100644 --- a/package.json +++ b/package.json @@ -21,6 +21,7 @@ "fbjs": "^0.8.1", "inline-style-prefix-all": "^2.0.2", "lodash": "^4.13.1", + "react-dom": "^15.1.0", "react-textarea-autosize": "^4.0.2", "react-timer-mixin": "^0.13.3" }, @@ -53,13 +54,11 @@ "node-libs-browser": "^0.5.3", "react": "^15.1.0", "react-addons-test-utils": "^15.1.0", - "react-dom": "^15.1.0", "webpack": "^1.13.1", "webpack-dev-server": "^1.14.1" }, "peerDependencies": { - "react": "^15.1.0", - "react-dom": "^15.1.0" + "react": "^15.1.0" }, "author": "Nicolas Gallagher", "license": "BSD-3-Clause", diff --git a/src/index.js b/src/index.js index 03165cc1..65712f58 100644 --- a/src/index.js +++ b/src/index.js @@ -2,6 +2,7 @@ import './apis/PanResponder/injectResponderEventPlugin' import findNodeHandle from './modules/findNodeHandle' import ReactDOM from 'react-dom' +import ReactDOMServer from 'react-dom/server' // apis import Animated from 'animated' @@ -45,9 +46,13 @@ import PointPropType from './apis/StyleSheet/PointPropType' Animated.inject.FlattenStyle(StyleSheet.flatten) const ReactNative = { + // top-level API findNodeHandle, render: ReactDOM.render, unmountComponentAtNode: ReactDOM.unmountComponentAtNode, + // web-only + renderToStaticMarkup: ReactDOMServer.renderToStaticMarkup, + renderToString: ReactDOMServer.renderToString, // apis Animated: {