Closed imdmitrykravchenko closed 3 years ago
I've held off on this until somebody asked for it.
I have an idea on how to handle this elegantly, avoiding some of the pitfalls koa has. The basic idea is when setting the body, you can instead provide a callback.
Example:
ctx.response.body = (stream: Writable) => {
ReactDOMServer.renderToNodeStream(element).pipe(stream);
}
Will this work for you?
P.S.: I'm very interested in having first-class React support via a middleware. Ideally I just want you to be able to call:
ctx.response.body = <div>hello world</div>;
This is something I'll tackle soon, but if it sounds interesting to contribute to a curveball/react package, let me know!
I tried to implement a react middleware. It works! And didn't need these changes.
With this middleware, you can simply do:
ctx.response.body = <html><div>hi</div</html>;
and it will just work.
Hello! Thanks for framework, it works just great.
I'm wondering if it has any approach for working with streams?
I'd like to render React on the server side using renderToNodeStream method, but cannot find such methods like
pipe
inResponse
class.Thanks in advance!