Container

Container is a Group wrapper that exposes typed imperative methods for dynamic node insertion and removal

import { Container } from "@roku-sdk/components";
Container(props: IContainerProps): JSX.Element

Description

Container is a Group wrapper that exposes typed imperative methods for dynamic node insertion and removal.

This component is designed for advanced pooling patterns where nodes need to be reparented at runtime without triggering full reactive re-renders. It wraps the raw tmTransaction.insertNode/removeNode calls with a typed API, eliminating the need for as any casts and eslint-disable comments.

Parameters

NameTypeDescription
propsIContainerProps

Example

import { Container, ContainerRef } from "@roku-sdk/components";

const PooledGrid: Component = () => {
    let slotContainerRef!: ContainerRef;

    createEffect(() => {
        const node = pool.acquire();
        slotContainerRef.insertNode(node.element);
    });

    return (
        <Container ref={(el) => (slotContainerRef = el)}>
            {/* Pooled nodes are inserted here dynamically */}
        </Container>
    );
};

Types

IContainerProps

Props for the Container component.

NameTypeDescription
children?ElementChild elements to render inside the container.
ref?(ref: ContainerRef) => voidCallback ref to receive the ContainerRef with imperative methods.

Extends Omit<IGroupProps, "ref">.

ContainerRef

Reference type for the Container component.

Extends ComponentRef with imperative methods for dynamic node insertion and removal. This provides a typed public API for pooling patterns that need to reparent nodes at runtime.

Example

let containerRef!: ContainerRef;

// Acquire a pooled node and insert it
const node = pool.acquire();
containerRef.insertNode(node.element);

// Later, remove the node (returns it to pool)
containerRef.removeNode(node.element);
pool.release(node);
NameTypeDescription
insertNode(node: DomNode) => voidInserts a node as a child of this container. The node is appended to the end of the children list.
removeNode(node: DomNode) => voidRemoves a node from this container. See below.

Extends ComponentRef<IGroupProps>.

ContainerRef.removeNode

Removes a node from this container. The node is marked for removal and will be detached on the next commit.

On firmware 15.2.x the parent link is the only strong reference to a SceneGraph node, so a committed detach destroys it and a later insertNode of the same node hands the render thread a deleted reference. Pooling that has to run on 15.2.x should reparent through ContainerRef.insertNode into a hidden container rather than detaching.


What’s Next

Did this page help you?