DEV Community

Discussion on: How to server-side render React, hydrate it on the client and combine client and server routes

Collapse
 
roscioli profile image
Octavio Dimitri Roscioli • Edited

Question: Why are you setting up redux both server side and client side? Should the server and client redux stores be instantiated with the same reducer? What ever happened to Don't Repeat Yourself (DRY)? Aren't we passing the initial state to the front end anyway (so then we're creating a store on the front end with that)?

I am asking with pure curiosity... Learning SSR right now and I've found this demo to be extremely helpful. Just confused on this.

Would also love a little more clarification why there is a react-router-dom router set up on the front and back end, but that can be answered separately.

Collapse
 
marvelouswololo profile image
MarvelousWololo

Hey, bro! What's up? I'm actually not using Redux here. But initiate it on the server could be useful in case you want to dispatch some stuff on the server first. :)

I'm glad you found it useful!

The react-router is set up both on the server and client because you need a root provider for your React app in both cases. Cheers!

Collapse
 
biquet93 profile image
biquet93

hi here, im late sorry :)
why do you need react-router for client and server, if i cancel the client webpack config, and i'm using only the server webpack config it's working, but there is no code-splitting , and i don't understand why i can't display the tutorial anymore. I thought, 'src/index' was sufficient for all application's requests, what did i miss ?

Thread Thread
 
marvelouswololo profile image
MarvelousWololo

Hi biquet93!

It's okay, np. I think your question is related to the 'hydration' of the app so I will share a link to the official docs where they do a great job explaining it. OK? Other than that it might be helpful to read the first paragraph of the tutorial again. Please don't be discouraged if you don't quite grasp it at first, it is a non trivial subject.

Here it is: reactjs.org/docs/react-dom.html#hy...