forked from alapini/parcel-react-ssr
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient.js
More file actions
34 lines (29 loc) · 895 Bytes
/
client.js
File metadata and controls
34 lines (29 loc) · 895 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// Entry point for the browser
// Start your React application and add the required containers
// Here we have <BrowserRouter /> for react-router
import { rehydrateMarks } from 'react-imported-component';
import React from 'react';
import ReactDOM from 'react-dom';
import { BrowserRouter } from 'react-router-dom';
import importedComponents from './imported'; // eslint-disable-line
import App from './App';
const element = document.getElementById('app');
const app = (
<BrowserRouter>
<App />
</BrowserRouter>
);
// In production, we want to hydrate instead of render
// because of the server-rendering
if (process.env.NODE_ENV === 'production') {
// rehydrate the bundle marks
rehydrateMarks().then(() => {
ReactDOM.hydrate(app, element);
});
} else {
ReactDOM.render(app, element);
}
// Hot reload is that easy with Parcel
if (module.hot) {
module.hot.accept();
}