Skip to main content

Children

Declares children of an instance when paired with New.

TypeSinceScoped
Declaration0.0.1No

Constructor​

[Children] = Instance | {Instance} | Computed

Usage​

New("Frame", {
[Children] = {
New("TextLabel", {
Text = "Hello",
}),
},
})

A single child can be passed without wrapping it in a table:

New("Frame", {
[Children] = New("UICorner", {}),
})

Numeric keys in New's property table are treated as implicit children with the same behavior:

New("Frame", {
Size = UDim2.fromScale(1, 1),

New("TextLabel", {
Text = "Hello",
}),
})

Reactive children​

Pass a Computed that returns a table of instances. When the computed updates, removed children are destroyed and new ones are parented. Cleanup also runs when the parent is destroyed.

local Names = Value({"Bob", "Rob", "Billy"})

New(ExistingFrame, {
[Children] = Computed(function(Use)
local Labels = {}

for _, Name in Use(Names) do
table.insert(Labels, New("TextLabel", {
Text = Name,
}))
end

return Labels
end),
})

Names.Value = {"Jon"} -- Old labels destroyed; one new label created

Only Computed instances are treated as reactive children (not arbitrary states). Prefer ForPairs when mapping keyed collections, then wrap or compose as needed for child tables.