renderApplication() supports async initial render

Reviewed By: sahrens

Differential Revision: D6339469

fbshipit-source-id: d832de936c50edcdc6953b72b5ad18ce1b652187
This commit is contained in:
Brian Vaughn 2017-11-17 13:30:06 -08:00 committed by Facebook Github Bot
parent ad89ea7b50
commit 1b22d49ae8
1 changed files with 23 additions and 3 deletions

View File

@ -30,12 +30,32 @@ function renderApplication<Props: Object>(
) {
invariant(rootTag, 'Expect to have a valid rootTag, instead got ', rootTag);
ReactNative.render(
let renderable = (
<AppContainer rootTag={rootTag} WrapperComponent={WrapperComponent}>
<RootComponent {...initialProps} rootTag={rootTag} />
</AppContainer>,
rootTag,
</AppContainer>
);
// If the root component is async, the user probably wants the initial render
// to be async also. To do this, wrap AppContainer with an async marker.
// For more info see https://fburl.com/tjpe0gpx
if (
RootComponent.prototype != null &&
RootComponent.prototype.unstable_isAsyncReactComponent === true
) {
// $FlowFixMe This is not yet part of the official public API
class AppContainerAsyncWrapper extends React.unstable_AsyncComponent {
render() {
return this.props.children;
}
}
renderable = (
<AppContainerAsyncWrapper>{renderable}</AppContainerAsyncWrapper>
);
}
ReactNative.render(renderable, rootTag);
}
module.exports = renderApplication;