Total Complexity | 1 |
Complexity/F | 1 |
Lines of Code | 30 |
Function Count | 1 |
Duplicated Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | import React from 'react'; |
||
2 | import { Provider } from 'react-redux'; |
||
3 | import { renderToString } from 'react-dom/server'; |
||
4 | import createMemoryHistory from 'history/createMemoryHistory'; |
||
5 | import { ConnectedRouter } from 'react-router-redux'; |
||
6 | |||
7 | import setupStore from 'client/store'; |
||
8 | import Router from 'client/router'; |
||
9 | import template from 'client/index.html'; |
||
10 | |||
11 | export default function serverSideRender() { |
||
12 | const history = createMemoryHistory(); |
||
13 | const store = setupStore(history); |
||
14 | const state = store.getState(); |
||
15 | |||
16 | const rendered = renderToString( |
||
17 | <Provider store={store}> |
||
18 | <ConnectedRouter history={history}> |
||
19 | <Router /> |
||
20 | </ConnectedRouter> |
||
21 | </Provider>, |
||
22 | ); |
||
23 | |||
24 | const page = template |
||
25 | .replace('<!-- CONTENT -->', rendered) |
||
26 | .replace('"-- STORES --"', JSON.stringify(state)); |
||
27 | |||
28 | return page; |
||
29 | } |
||
30 |