mirror of
				https://github.com/aleleba/create-react-ssr.git
				synced 2025-10-31 06:00:39 -06:00 
			
		
		
		
	PR-753737: Se agrega hydrate y se inyecta initial state en SRR.
This commit is contained in:
		| @@ -42,7 +42,7 @@ if(env === 'development'){ | ||||
|     })); | ||||
| } | ||||
|  | ||||
| const setResponse = (html) => { | ||||
| const setResponse = (html, preloadedState) => { | ||||
|     return(` | ||||
|     <!DOCTYPE html> | ||||
|     <html lang="es"> | ||||
| @@ -55,6 +55,9 @@ const setResponse = (html) => { | ||||
|         </head> | ||||
|         <body> | ||||
|             <div id="app">${html}</div> | ||||
|             <script> | ||||
|                 window.__PRELOADED_STATE__ = ${JSON.stringify(preloadedState).replace(/</g, '\\u003c')} | ||||
|             </script> | ||||
|             <script src="assets/app.js" type="text/javascript"></script> | ||||
|         </body> | ||||
|     </html> | ||||
| @@ -63,6 +66,7 @@ const setResponse = (html) => { | ||||
|  | ||||
| const renderApp = (req, res) => { | ||||
|     const store = createStore(reducer, initialState) | ||||
|     const preloadedState = store.getState(); | ||||
|     const html = renderToString( | ||||
|         <Provider store={store}> | ||||
|             <StaticRouter location={req.url}> | ||||
| @@ -70,7 +74,7 @@ const renderApp = (req, res) => { | ||||
|             </StaticRouter> | ||||
|         </Provider> | ||||
|     ) | ||||
|     res.send(setResponse(html)); | ||||
|     res.send(setResponse(html, preloadedState)); | ||||
| }; | ||||
|  | ||||
| app.get('*', renderApp) | ||||
|   | ||||
		Reference in New Issue
	
	Block a user