For AI agents: the complete documentation index is available at /next/llms.txt, the full documentation bundle is available at /next/llms-full.txt, and this page is available as Markdown at /next/api/react/Function.createPortal.md.
  • English
  • @lynx-js/react / createPortal

    Function: createPortal()

    function createPortal(vnode: ComponentChild, container: NodesRef): ReactNode

    Renders vnode into container instead of the current component's position in the element tree, while keeping it in the React tree.

    container is a NodesRef, obtained either from a callback ref or from lynx.createSelectorQuery().select(...).

    Availability
    • Added in @lynx-js/react 0.121.0.
    • The declared return type is ReactNode since 0.123.3. In 0.123.2 and earlier it is Preact's VNode<any> | null; there is no runtime difference.

    Parameters

    ParameterTypeDescription
    vnodeComponentChildThe React node to render into container.
    containerNodesRefThe NodesRef target to render into.

    Returns

    ReactNode

    A ReactNode placeholder to include in the JSX at the call site; the rendered output goes into container.

    Remarks

    Context still flows across the portal boundary, and state updates inside the portal behave like they do in any other component. A few behaviors differ from react-dom:

    • Events do not bubble along the React tree. ReactLynx follows Preact's approach, which has no synthetic event system, so events follow the actual element structure of the page.
    • The portaled subtree renders on the background thread only, and does not participate in main-thread first-screen rendering.
    • Mounting across pages or across native containers is not supported.

    Defined in

    @lynx-js/react/runtime/lib/snapshot/lynx/portals.d.ts:31

    Example

    Except as otherwise noted, this work is licensed under a Creative Commons Attribution 4.0 International License, and code samples are licensed under the Apache License 2.0.