3 ms·
The fact that componentDidMount only gets called on the client seems like it would make it a good place to hook up progressive enhancement after rendering a bas
by insin 12y ago
The fact that componentDidMount only gets called on the client seems like it would make it a good place to hook up progressive enhancement after rendering a basic isomorphic version on the server (e.g. a <select multiple> which you enhance with dynamic features only when JavaScript runs on the client) - for server rendering, it would be too late as you only get one render and need to do everything up front.
I've been playing [1] with isomorphic forms using react-router - it uses a static willTransitionTo() hook on the constructor of components which do route handling for the equivalent of request handling, which seems to work well in the limited cases I've tried so far.
For API requests, you can use a request library which has the same API on client and server - superagent and axios seem to work well.
[1] https://isomorphic-lab.herokuapp.com/addthing https://isomorphic-lab.herokuapp.com/addthing
- Todd 12y agoI'm also using react-router. I've been pretty happy with it. I will take a look at willTransitionTo again. In the meantime, I'm doing what you suggest--rendering a basic initial view. In the end, you are only going to be able to go so far on the server before you have to wait for the client side mounting event. You can render a complete page, with forms and the rest, but it won't be interactive until the mount anyway.
- insin 12y agoIt can be! That's one of the the benefits of the isomorphic approach - for the bits you want to use it in, it should degrade to regular forms 'n links round-tripping.