When renderToString is Appropriate
You'll learn when blocking HTML generation with renderToString is the right choice for your project.
The Right Tool for Specific Jobs
Not every application needs streaming or complex interactivity. renderToString synchronously generates complete HTML in one blocking call, which makes it perfect for certain scenarios where simplicity and completeness matter more than progressive rendering.
Where renderToString Shines
Static Site Generation
When you're building pages at build time (not request time), renderToString is ideal. You generate complete HTML once, save it to disk, and serve it repeatedly. There's no user waiting, so blocking is irrelevant.
Simple Pages
For straightforward marketing pages, documentation, or landing pages with minimal interactivity, renderToString gives you a complete HTML string immediately. No streaming complexity needed.
Complete HTML Requirements
Some scenarios demand the entire HTML document upfront:
- Email templates rendered with React
- PDF generation from React components
- RSS feed content
- Systems expecting a complete HTML string, not a stream
The Trade-Off
Think of renderToString like taking a photograph versus recording a video. The photograph (complete HTML) is simpler when you just need a complete snapshot. Streaming is like video—better for progressive display but more complex.
You're trading Time to First Byte for simplicity. If your server can generate the HTML quickly and the page is relatively small, the blocking wait is acceptable.
When NOT to Use It
Avoid renderToString for large, data-heavy applications where users would wait noticeably. If your page takes seconds to generate, streaming would show content progressively instead of a blank screen.
Key Takeaway: Use renderToString for static builds, simple pages, email templates, and scenarios where you need complete HTML immediately and blocking generation is acceptable. For complex applications where users are waiting, streaming is better.