From ebd57d2bd6c39b51a455b76018737e2957e146ef Mon Sep 17 00:00:00 2001 From: Kyle Mathews Date: Tue, 11 Oct 2016 15:55:12 -0700 Subject: [PATCH] Add new API to let people wrap the root component E.g. for adding Redux support. --- lib/intermediate-representation-dir/app.js | 19 ++++++++++++------- .../production-app.js | 6 +++++- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/lib/intermediate-representation-dir/app.js b/lib/intermediate-representation-dir/app.js index 0242e59e2aae6..9e7abc520cf07 100644 --- a/lib/intermediate-representation-dir/app.js +++ b/lib/intermediate-representation-dir/app.js @@ -4,15 +4,18 @@ apiRunner('clientEntry') import React from 'react' import ReactDOM from 'react-dom' -import { AppContainer } from 'react-hot-loader' +import { AppContainer as HotContainer } from 'react-hot-loader' const rootElement = document.getElementById(`react-mount`) let Root = require('./root') if (Root.default) { Root = Root.default } + +// Let site, plugins wrap the site e.g. for Redux. +const NewRoot = apiRunner('wrapRootComponent', { Root: Root }, Root) ReactDOM.render( - - - , + + + , rootElement ) @@ -20,10 +23,12 @@ if (module.hot) { module.hot.accept(`./root`, () => { let NextRoot = require('./root') if (NextRoot.default) { NextRoot = NextRoot.default } + // Let site, plugins wrap the site e.g. for Redux. + const NewRoot = apiRunner('wrapRootComponent', { Root: NextRoot }, NextRoot) ReactDOM.render( - - - , + + + , rootElement ) }) diff --git a/lib/intermediate-representation-dir/production-app.js b/lib/intermediate-representation-dir/production-app.js index 540d2789bd8ca..664c295e22c1a 100644 --- a/lib/intermediate-representation-dir/production-app.js +++ b/lib/intermediate-representation-dir/production-app.js @@ -52,11 +52,15 @@ function shouldUpdateScroll (prevRouterProps, { location: { pathname } }) { } match({ history: browserHistory, routes: rootRoute }, (error, redirectLocation, renderProps) => { - ReactDOM.render(( + const Root = () => ( {apiRunner('onRouteUpdate', currentLocation)}} /> + ) + const NewRoot = apiRunner('wrapRootComponent', { Root: Root }, Root) + ReactDOM.render(( + ), typeof window !== `undefined` ? document.getElementById(`react-mount`) : void 0) })