Answer the question
In order to leave comments, you need to log in
What is an isomorphic application and how to create one?
What does isomorphic application on react + nodejs mean? I do not quite understand what should happen in the end?
Just need to add
app.get('/', (req, res) => {
const componentHTML = ReactDom.renderToString(<App />);
return res.end(renderHTML(componentHTML));
});
const assetUrl = process.env.NODE_ENV !== 'production' ? 'http://localhost:8050' : '/'; // Это url сервера же, не фронта?
function renderHTML(componentHTML) {
return `
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Hello React</title>
<link rel="stylesheet" href="${assetUrl}/public/assets/styles.css">
</head>
<body>
<div id="react-view">${componentHTML}</div>
<script type="application/javascript" src="${assetUrl}/public/assets/bundle.js"></script>
</body>
</html>
`;
}
Answer the question
In order to leave comments, you need to log in
Read any topical article on this topic.
1. In the simplest case, you have two entry points server (with ReactDOMServer.renderToString) and client (with ReactDOM.hydrate).
2. State can be received on the server and transmitted to the client, something like this:
In configureStore:
export = function (initialState: {} = {}) {
if (__CLIENT__) {
initialState = JSON.parse(JSON.stringify(window.__INITIAL_STATE__));
}
return createStore(combineReducers({ ...rootReducer }), initialState, enhancer);
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question