Roact exposes its entire public surface through a single module returned byDocumentation 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.
require(Roact). This page documents every function, component type, and special constant available on that table. All examples assume you have already required Roact and assigned it to a local variable named Roact.
Methods
Roact.createElement
component. Elements are lightweight descriptions of what a Roblox Instance should look like — think of them as blueprints rather than the real thing. Roact uses these descriptions during mounting and reconciliation to create and update actual Roblox Instances.
component can be a string (a Roblox host class name such as "Frame"), a function component, or a table produced by Component:extend. The optional children argument is shorthand for placing a Roact.Children key inside props; it should be a dictionary mapping string names to child elements.
The component to create an element for. Pass a Roblox class name string for host components, a function for function components, or a class table returned by
Component:extend for stateful components.A dictionary of properties and special prop-marker keys to apply to this element. Pass
nil or omit to use no props.A dictionary of name-to-element pairs that become the children of this element. Equivalent to setting
props[Roact.Children] directly.RoactElement — a lightweight, immutable description of the desired UI.
Roact.createFragment
Added in Roact 1.0.0.
render method without needing a wrapping container like a Frame. They are transparent to the Roblox Instance hierarchy — children of a fragment are placed directly into the fragment’s parent.
A dictionary of name-to-element pairs to include in the fragment. The keys are used as child names within the parent’s children.
RoactFragment — an element-like value that renders its children without a wrapping Instance.
Roact.mount
parent and naming it with key. This is the entry point for putting a Roact component tree into the game world. The returned RoactTree is an opaque handle that you pass to Roact.update and Roact.unmount.
The root element to mount. Must be a value returned by
Roact.createElement or Roact.createFragment.The Roblox Instance to parent the root Instance into. Omit to leave the tree unparented.
The
Name property to assign to the root Instance. Omit to use Roact’s default naming.RoactTree — an opaque handle representing the live component tree.
Roact.update
RoactTree is the same object that was passed in.
The handle returned by a previous call to
Roact.mount.The new element to reconcile the tree against.
RoactTree — the same handle that was passed in, now updated.
Roact.unmount
RoactTree and all its descendants, firing willUnmount on every stateful component in the tree. The associated Roblox Instances are also destroyed. After calling unmount, the tree handle is no longer valid.
The handle returned by
Roact.mount. Must not be a Roblox Instance.Roact.oneChild
children is nil or empty, it returns nil. If children contains exactly one child, that child element is returned. If children contains more than one child, an error is thrown — this is intentional, to surface programming errors in components that expect at most one child.
The
self.props[Roact.Children] table, or any dictionary of named elements.RoactElement | nil — the single child element, or nil if there are no children.
Roact.createBinding
Added in Roact 1.0.0.
Binding object. The second is an updater function; call it with a new value to push that value through all subscribers of the binding.
The starting value of the binding. Can be any Lua value.
Binding, (newValue: any) -> void — the binding object and its updater function.
Binding:getValue
Binding:map
mappingFunction to the upstream binding’s value. The derived binding updates automatically whenever the upstream binding updates.
Roact.joinBindings
Added in Roact 1.1.0.
Binding:map on the result to transform the combined value.
A dictionary (or array) of
Binding values to combine. All values must be bindings.Binding — a single binding whose value mirrors the current values of all inputs.
Roact.createRef
Roact.Ref prop marker. A ref gives you direct access to the underlying Roblox Instance rendered by a host component. Refs are a kind of binding: call ref:getValue() to retrieve the current Instance.
Returns: Ref — a ref object with a getValue() method and a deprecated current field.
Roact.forwardRef
Added in Roact 1.4.0.
forwardRef is the sanctioned way to pass them through.
A function with the signature
function(props, ref) -> RoactElement. props is the component’s props table (with the ref removed), and ref is the forwarded ref that should be assigned to a host element via [Roact.Ref].RoactComponent — a component that can be used with Roact.createElement.
Roact.createContext
Added in Roact 1.3.0.
Provider and Consumer. Context lets you share a value (such as a theme, locale, or data store) through an arbitrary depth of the component tree without threading it through every intermediate component’s props.
defaultValue is used when a Consumer has no Provider ancestor. It is the responsibility of the application author to decide whether that situation is valid.
The fallback value given to any
Consumer that is not a descendant of a matching Provider.{ Provider: Component, Consumer: Component } — the context provider and consumer pair.
Provider props
The value to make available to all descendant
Consumer components. When this prop changes, all reachable consumers are re-rendered.Child elements to render underneath the provider.
Consumer props
A function with the signature
function(value) -> RoactElement | nil. Called every time the consumer renders, receiving the current context value.Roact.setGlobalConfig
require result), it should be called once at the root of your project before any components are mounted.
A dictionary of config key strings to boolean values. Unknown keys will cause an error.
| Key | Description |
|---|---|
typeChecks | Validates types on Roact’s public API (props, arguments to createElement, etc.) |
internalTypeChecks | Validates types inside Roact’s internal implementation. Primarily useful when debugging Roact itself. |
elementTracing | Captures a stack trace at each createElement call site and attaches it to the element for richer error messages. Also enables getElementTraceback. |
propValidation | Runs each component’s validateProps static method before every prop update. |
Component Types
Roact provides three built-in component types that cover the most common use cases.Roact.Component
The base class for all stateful components. Extend it withRoact.Component:extend("ComponentName") to create a new class. Stateful components have access to self.props, self.state, and the full lifecycle API.
Roact.PureComponent
An extension ofRoact.Component that overrides shouldUpdate with a shallow equality check on both props and state. A PureComponent will skip re-rendering if its new props and state are shallowly equal to the previous values, which can offer significant performance gains when used with immutable data patterns (such as those enforced by Rodux).
Roact.Portal
A special component that renders its children into a Roblox Instance outside of the normal component tree. This is useful for UI elements like modal dialogs or tooltips that need to live at the top of the Instance hierarchy but be controlled by a deeply-nested component. Portals are created withRoact.createElement and require a target prop pointing to an existing Roblox Instance that is not managed by Roact.
The Roblox Instance into which the portal’s children will be placed. Must not be a Roact-managed Instance.
Prop Markers
Roact exports four special constant values used as keys inside host element prop tables. Because these values must be distinguishable from ordinary string property names, they are unique Lua objects rather than strings.| Constant | Description |
|---|---|
Roact.Event | Index with an event name (Roact.Event.Activated) to connect a callback to that Roblox Instance event. |
Roact.Change | Index with a property name (Roact.Change.Text) to connect a callback via GetPropertyChangedSignal. |
Roact.Ref | Assign a ref object or function to receive a handle to the underlying Roblox Instance. |
Roact.Children | The key Roact uses internally to store child elements on a props table; read it in components to access children. |
ref.current field — is on the Prop Markers page.
Special Constants
Roact.None
Roact.None is a sentinel value used to remove a field from component state when calling setState or returning from getDerivedStateFromProps. In Lua, setting a table key to nil simply omits it, so there is no way to express “please delete this key” using plain nil. Roact.None fills that gap.