is created and the React tree rendered into it.
// On unmount, root.unmount() is called and the container div is removed from the DOM.
```
--------------------------------
### singleSpaReact with hydrateRoot — SSR hydration
Source: https://context7.com/single-spa/single-spa-react/llms.txt
To enable server-side rendering (SSR) hydration, use `hydrateRoot` instead of `createRoot`. This attaches React event listeners to server-rendered HTML without discarding existing DOM nodes. The `domElementGetter` must point to the element that already contains the SSR markup. When using `hydrateRoot`, the container element is not automatically removed on unmount.
```APIDOC
## singleSpaReact with hydrateRoot — SSR hydration
### Description
Use `hydrateRoot` instead of `createRoot` for server-side rendering (SSR) hydration. This attaches React event listeners to server-rendered HTML without discarding existing DOM nodes. The `domElementGetter` must point to the element that already contains the SSR markup. The container element is not removed on unmount when using `hydrateRoot`.
### Method
`singleSpaReact(opts)` with `hydrateRoot` passed in options.
### Parameters
#### Options (`opts`)
- **createElement** (function) - Required - React's `createElement` function.
- **useEffect** (function) - Required - React's `useEffect` hook.
- **hydrateRoot** (function) - Required (for SSR) - React DOM's `hydrateRoot` function.
- **domElementGetter** (function) - Required - A function that returns the DOM element containing the SSR markup.
- **renderReactNode** (function) - Required - A function that receives single-spa props and returns a `ReactNode` or a `Promise
`.
### Request Example
```typescript
import { createElement, useEffect } from "react";
import { hydrateRoot } from "react-dom/client";
import singleSpaReact from "single-spa-react";
import App from "./App";
export const { init, mount, unmount } = singleSpaReact({
createElement,
useEffect,
hydrateRoot, // use hydrateRoot instead of createRoot
domElementGetter: () => document.getElementById("ssr-container"),
renderReactNode(props) {
return ;
},
});
```
### Response
Returns an object with single-spa lifecycle hooks: `{ init, mount, update, unmount }`.
```
--------------------------------
### SingleSpaReactParcelProps Type Reference
Source: https://context7.com/single-spa/single-spa-react/llms.txt
Reference for all props accepted by the `` component. You must provide either the `mountParcel` prop or a `singleSpaContext` that resolves `mountParcel`.
```typescript
import type { SingleSpaReactParcelProps } from "single-spa-react/parcel";
import type { Context } from "react";
import type { AppProps, ParcelConfig } from "single-spa";
const parcelProps: SingleSpaReactParcelProps = {
// Required: static config object or async loader returning a config
config: myParcelConfig,
// config: async () => (await import("./parcel")).default,
// One of these must resolve mountParcel:
mountParcel: mountRootParcel, // explicit prop
// singleSpaContext: MyAppContext, // React context carrying AppProps
// DOM wrapper
wrapWith: "div", // default
wrapWithProps: { id: "parcel-root" },
// Callbacks
parcelDidMount: () => {},
parcelDidUpdate: () => {},
handleError: (err: Error) => {}, // suppress throws, handle manually
};
```
--------------------------------
### SingleSpaReactParcelProps Type
Source: https://context7.com/single-spa/single-spa-react/llms.txt
Reference for all props accepted by the `` component, detailing configuration, mounting, DOM wrapper customization, and lifecycle callbacks.
```APIDOC
## `SingleSpaReactParcelProps` type — Full `` props reference
```typescript
import type { SingleSpaReactParcelProps } from "single-spa-react/parcel";
import type { Context } from "react";
import type { AppProps, ParcelConfig } from "single-spa";
const parcelProps: SingleSpaReactParcelProps = {
// Required: static config object or async loader returning a config
config: myParcelConfig,
// config: async () => (await import("./parcel")).default,
// One of these must resolve mountParcel:
mountParcel: mountRootParcel, // explicit prop
// singleSpaContext: MyAppContext, // React context carrying AppProps
// DOM wrapper
wrapWith: "div", // default
wrapWithProps: { id: "parcel-root" },
// Callbacks
parcelDidMount: () => {},
parcelDidUpdate: () => {},
handleError: (err: Error) => {}, // suppress throws, handle manually
};
```
```
--------------------------------
### Component
Source: https://context7.com/single-spa/single-spa-react/llms.txt
The `` component from `single-spa-react/parcel` allows you to render any single-spa parcel (regardless of framework) as a child within a React component tree. It mounts the parcel into a generated wrapper element.
```APIDOC
## `` component — Render a single-spa parcel inside a React tree
Imported from `single-spa-react/parcel`. Mounts a single-spa parcel (any framework) as a child of a React component tree. The parcel is mounted into a generated wrapper element (`` by default). `mountParcel` can be supplied directly or read from a `singleSpaContext` context that carries the single-spa `AppProps`.
```tsx
// src/components/WidgetShell.tsx
import Parcel from "single-spa-react/parcel";
import { mountRootParcel } from "single-spa";
// Static config object
import widgetConfig from "@org/widget/single-spa-config";
export function WidgetShell() {
return (
console.log("parcel mounted")}
parcelDidUpdate={() => console.log("parcel updated")}
handleError={(err) => console.error("parcel error:", err)}
// Extra props forwarded to the parcel
userId="u_123"
theme="dark"
/>
);
}
// Lazy-loading parcel config via async function
export function LazyWidget() {
return (
{
const mod = await import("@org/lazy-widget/single-spa-config");
return mod.default;
}}
mountParcel={mountRootParcel}
handleError={(err) => console.error(err)}
/>
);
}
```
```
=== COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.