mirror of
				https://github.com/aleleba/create-react-ssr.git
				synced 2025-10-31 06:00:39 -06:00 
			
		
		
		
	PR-753737: Se agregaj Redux al proyecto y al SSR.
This commit is contained in:
		| @@ -1,3 +1,5 @@ | ||||
| require('dotenv').config(); | ||||
|  | ||||
| require('ignore-styles'); | ||||
|  | ||||
| require('@babel/register')({ | ||||
|   | ||||
| @@ -11,7 +11,14 @@ import webpackHotMiddleware from 'webpack-hot-middleware'; | ||||
| //Dependencies of SSR | ||||
| import React from 'react'; | ||||
| import { renderToString } from 'react-dom/server'; | ||||
| //Router | ||||
| import { StaticRouter } from "react-router-dom/server"; | ||||
| //Redux | ||||
| import { createStore } from 'redux'; //, applyMiddleware | ||||
| import { Provider } from 'react-redux'; | ||||
| import reducer from '../frontend/reducers'; | ||||
| import initialState from '../frontend/reducers/initialState'; | ||||
| //App | ||||
| import App from '../frontend/components/App'; | ||||
|  | ||||
| const { env, port } = config | ||||
| @@ -55,10 +62,13 @@ const setResponse = (html) => { | ||||
| } | ||||
|  | ||||
| const renderApp = (req, res) => { | ||||
|     const store = createStore(reducer, initialState) | ||||
|     const html = renderToString( | ||||
|         <StaticRouter location={req.url}> | ||||
|             <App /> | ||||
|         </StaticRouter> | ||||
|         <Provider store={store}> | ||||
|             <StaticRouter location={req.url}> | ||||
|                 <App /> | ||||
|             </StaticRouter> | ||||
|         </Provider> | ||||
|     ) | ||||
|     res.send(setResponse(html)); | ||||
| }; | ||||
|   | ||||
		Reference in New Issue
	
	Block a user