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
Usage
Wrapping a chart library
Wrapping a rich text editor
With reactive data via domEffect
Bridge Vertz reactivity into the unmanaged subtree usingdomEffect:
Hydration behavior
During server-side rendering,Foreign renders as an empty container element (e.g., <div></div>). On hydration:
- The container element is claimed by the hydration cursor
- Children are not walked — the cursor advances past the container
onReadyfires after hydration completes (post-hydrationonMounttiming)- Any server-rendered children inside the container are preserved for the
onReadycallback to use or replace
Cleanup
The function returned fromonReady 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.