Skip to main content
Foreign renders a container element whose children are owned by external (non-Vertz) code. During hydration, the container is claimed but its children are not walked — external content is preserved. Use Foreign to integrate third-party libraries that manage their own DOM (D3, Chart.js, CodeMirror, map libraries, etc.).

Signature

Props

PropTypeDefaultDescription
tagkeyof HTMLElementTagNameMap | keyof SVGElementTagNameMap'div'HTML/SVG tag for the container element
onReady(container: HTMLElement | SVGElement) => (() => void) | voidCalled when the container is mounted and ready for external DOM manipulation. Return a cleanup function for unmount.
idstringElement id attribute
classNamestringCSS class name
stylePartial<CSSStyleDeclaration>Inline styles (camelCase object)
childrenneverNot supported. External code manages children via onReady.

Usage

Wrapping a chart library

Wrapping a rich text editor

With reactive data via domEffect

Bridge Vertz reactivity into the unmanaged subtree using domEffect:

Hydration behavior

During server-side rendering, Foreign renders as an empty container element (e.g., <div></div>). On hydration:
  1. The container element is claimed by the hydration cursor
  2. Children are not walked — the cursor advances past the container
  3. onReady fires after hydration completes (post-hydration onMount timing)
  4. Any server-rendered children inside the container are preserved for the onReady callback to use or replace
This means external libraries can safely manipulate the container’s children without interfering with Vertz’s hydration of surrounding elements.

Cleanup

The function returned from onReady runs when the component unmounts (e.g., route change, conditional removal). Use it to tear down third-party library instances, remove event listeners, or cancel animations.