-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
13 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,24 @@ | ||
--- | ||
'@astrojs/react': minor | ||
'astro': patch | ||
--- | ||
|
||
Exposes a `renderer` object from `@astrojs/react/server.js` and `@astrojs/react/server17.js`. This is useful when using the Container API for on-demand pages: | ||
Adds a new function called `addServerRenderer` to the Container API. Use this function to manually store renderers inside the instance of your container. | ||
|
||
This new function should be preferred when using the Container API in environments like on-demand pages: | ||
|
||
```ts | ||
import type {APIRoute, SSRLoadedRenderer} from "astro"; | ||
import type {APIRoute} from "astro"; | ||
import { experimental_AstroContainer } from "astro/container"; | ||
import { renderer } from '@astrojs/react/server.js'; | ||
import Component from "../components/button.jsx" | ||
import reactRenderer from '@astrojs/react/server.js'; | ||
import vueRenderer from '@astrojs/vue/server.js'; | ||
import ReactComponent from "../components/button.jsx" | ||
import VueComponent from "../components/button.vue" | ||
|
||
export const GET: APIRoute = async (ctx) => { | ||
const renderers: SSRLoadedRenderer[] = [renderer]; | ||
const container = await experimental_AstroContainer.create({ | ||
renderers | ||
}); | ||
const container = await experimental_AstroContainer.create(); | ||
container.addServerRenderer("@astrojs/react", reactRenderer); | ||
container.addServerRenderer("@astrojs/vue", vueRenderer); | ||
const vueComponent = await container.renderToString(VueComponent) | ||
return await container.renderToResponse(Component); | ||
} | ||
``` |