From a7376f23fd47618c17eb47eed51bc9d79e4cd59b Mon Sep 17 00:00:00 2001 From: Matthias Kretschmann Date: Tue, 27 Mar 2018 10:00:52 +0200 Subject: [PATCH] add react-snap --- package.json | 4 +++- src/index.js | 16 +++++++++------- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/package.json b/package.json index 7a19aa1..b5232e5 100644 --- a/package.json +++ b/package.json @@ -17,6 +17,7 @@ "eslint": "^4.19.1", "eslint-plugin-react": "^7.7.0", "jest-cli": "^22.4.3", + "react-snap": "^1.11.5", "stylelint": "^9.1.3", "stylelint-config-standard": "^18.2.0" }, @@ -31,6 +32,7 @@ "build-js": "react-scripts build", "build": "npm-run-all build-css build-js", "test": "npm run lint && react-scripts test --env=jsdom", - "eject": "react-scripts eject" + "eject": "react-scripts eject", + "postbuild": "react-snap" } } diff --git a/src/index.js b/src/index.js index e55ef8c..098f128 100644 --- a/src/index.js +++ b/src/index.js @@ -1,14 +1,16 @@ import React from 'react' -import ReactDOM from 'react-dom' +import { hydrate, render } from 'react-dom' import { BrowserRouter as Router } from 'react-router-dom' import './index.css' import App from './App' import registerServiceWorker from './registerServiceWorker' -ReactDOM.render( - - - , - document.getElementById('root') -) +const rootElement = document.getElementById('root') + +if (rootElement.hasChildNodes()) { + hydrate(, rootElement) +} else { + render(, rootElement) +} + registerServiceWorker()