Answer the question
In order to leave comments, you need to log in
How can I make an SSR React app using express?
Good afternoon, I decided to find out how to make an SSR application, but I came to a dead end. I usually refer to index.html.
<!DOCTYPE html>
<html>
<head>
<title>Todo</title>
<meta name="viewport" content="width=device-width initial-scale=1">
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">
<link href="https://fonts.googleapis.com/css?family=PT+Sans+Narrow" rel="stylesheet">
</head>
<body>
<div id="root"></div>
<script type="text/javascript" src="app.bundle.js"></script>
</body>
</html>
import React from 'react';
import {
AppContainer
} from 'react-hot-loader';
import ReactDOM from 'react-dom';
import Component from './components/App';
ReactDOM.render(
<AppContainer>
<Component />
</AppContainer>,
document.getElementById('root')
)
if(module.hot){
module.hot.accept(()=>{
ReactDOM.render(
<AppContainer>
<Component />
</AppContainer>,
document.getElementById('root')
)
})
}
Answer the question
In order to leave comments, you need to log in
More or less like this:
import React from 'react';
import { StaticRouter } from 'react-router'
import { Provider } from 'react-redux'
import ReactDOMServer from 'react-dom/server';
import Store from './store';
export default (Url, Component, Props = {}, Context = {}) => {
return ReactDOMServer.renderToString(
<Provider store={Store}>
<StaticRouter
location={Url}
context={Context}>
<Component {...Props}/>
</StaticRouter>
</Provider>
);
}
import reactRenderToString from './reactRenderToString'
import Component from '../client/routes/Home.jsx';
console.log(reactRenderToString('/', Component))
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question