Answer the question
In order to leave comments, you need to log in
A complete SSR example for react/redux?
Good afternoon! Can you please tell me a complete server side rendering example for react/redux? Is there such a thing?
I don’t understand how to make the components universal, perhaps it’s necessary to somehow transfer the state from the back to the client?!
Can I immediately pass the main component on the server when rendering?
Please give some advice on this subject.
Thank you!
Answer the question
In order to leave comments, you need to log in
Yes, the state is collected on the server for each client (request'a), let's say at the middleware level we collect the state (the current authorized user, some other global data), then the route handler works, we received some page data from the database and passed them as a context, something like this:
import React from 'react';
import { StaticRouter } from 'react-router'
import { Provider } from 'react-redux'
import ReactDOMServer from 'react-dom/server';
import App from './client/components/App.jsx'
ReactDOMServer.renderToString(
<Provider store={ReduxStore}>
<StaticRouter
location={Url}
context={Context}>
<App/>
</StaticRouter>
</Provider>
);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question