I'm trying to build a simple universal app using Express + Mongoose + React + Redux + Redux saga and run into some difficulties. How to dial with component's data dependencies with redux-saga? How to give component data depenting on wether it is ssr or client side (get is from Mongoose model or make a request)? Does anybody have an example of that?
Philip Davis
Software developer
There is no such thing as a simple universal app with those technologies you listed.
There are lots of ways to skin a cat, as the saying goes. The way I've solved that problem is to reference count my API calls in my sagas. The web request handler does a render pass and then checks to see if there are any pending calls. If no more calls are pending it sends a response. Otherwise, it goes back to waiting for the store state to change.
My components aren't aware of whether they're on the server or client. They're purely presentational. Even the sagas aren't aware because I'm using isomorphic-fetch to treat the client and server the same.
I don't have any examples I can show you right now... but I have a blog post planned on this topic.