Elements are the foundational building blocks of every Roact UI. Before any component logic runs or any Roblox Instances appear on screen, you describe what you want using elements — plain, lightweight Lua tables that capture a snapshot of your UI at a single point in time.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/Roblox/roact/llms.txt
Use this file to discover all available pages before exploring further.
What Are Elements?
An element is an immutable description of what a piece of UI should look like right now. You cannot modify an element after creating it, but creating new elements is extremely cheap, so Roact encourages you to produce them freely and often. When you need the UI to change, you simply describe the new desired state and hand it back to Roact. Elements are created withRoact.createElement. Host elements use a Roblox class name string — such as "Frame" or "TextLabel" — as their first argument. Roact maps these directly to the corresponding Roblox Instance types.
createElement Signature
| Argument | Type | Description |
|---|---|---|
component | string or component | A Roblox class name string ("Frame") or a Roact component. |
props | table | nil | Properties to apply. For host components these become Instance properties. |
children | table | nil | A dictionary of named child elements. |
Props
The second argument is a table of props. For host components (string class names), every key-value pair in this table is applied directly as a property on the resulting Roblox Instance.Children
The third argument is a dictionary of named child elements. Each key is an arbitrary name used by Roact to track the child across updates; each value is another element produced bycreateElement.
Mounting, Updating, and Unmounting
Creating an element alone doesn’t produce any Roblox Instances. You must mount the element to turn it into real UI. The three lifecycle functions below manage the full lifespan of a Roact tree.Mount the element
Call Mounting is the process of constructing component instances and their associated Roblox Instances for the first time.
Roact.mount to create a live UI tree from an element. Pass the element, a parent Instance, and an optional name for the root object. It returns a RoactTree handle you must hold on to.Update the tree
To change the UI, create a new element describing the desired state and pass it to As of Roact v1.0,
Roact.update along with the existing handle. Roact reconciles the old tree against the new one, making only the minimal set of changes needed.Roact.update returns the same tree object that was passed in. The handle remains valid. Reassigning it (as shown above) is conventional and safe, but the original variable continues to point to the same tree.Do not use a handle after passing it to
Roact.unmount. The handle is invalidated immediately, and any further calls using it will result in errors.Reconciliation
Reconciliation is Roact’s process of comparing an existing UI tree to a new element tree and efficiently updating only the Instances that have changed. Rather than tearing down and recreating everything, Roact computes the difference (diff) between the old and new virtual trees and applies targeted property changes to the real Roblox Instances. This is what makes theRoact.update call cheap even for large UI trees — unchanged subtrees are left completely untouched.
Full Example: Incrementing Counter
The example below puts everything together. Aclock function returns a fresh element tree each call, and Roact.update reconciles the tree every second. This is a complete LocalScript that can be placed in StarterPlayerScripts with Roact installed in ReplicatedStorage.