How can I render a astro component to a HTML string?

Viewed 261

I'd like to be able to have a dynamic page in Astro that renders out an Astro component. I've dug into the docs and code, and couldn't find a function like the one below (Asto.render). Ideally, I can pass properties into it. I'm looking for something similar to react.renderToString.

import Example from './components/Example.astro'

export async function get() {
  return {
    body: Astro.render(Example)
  };
}
1 Answers

Astro components are rendered on the server, so you can directly reference the included component and pass down props as you want.

// [title].astro

---
import Example from './components/Example.asto'
---

<Example message="Hey" />
Related