Roact’s reconciliation system is powerful, but it is not always the right tool. Re-rendering an entire component tree to update one animated property every frame would be far too expensive, and some Roblox Instance APIs simply need to be called directly rather than driven by props. For these cases Roact provides two complementary escape hatches: bindings for pushing values directly onto properties, and refs for obtaining a handle to the underlying Roblox Instance itself.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.
Bindings
Bindings are special objects that Roact knows how to unwrap. When you supply a binding as the value of a prop, Roact subscribes that property to the binding. Whenever the binding’s value changes, Roact updates only that specific property — no reconciliation pass, no component re-render. This makes bindings ideal for animations, dynamically resizing elements, gamepad selection state, and any other situation where you need frequent, targeted updates.Creating a Binding
Roact.createBinding was added in Roact 1.0.0.Roact.createBinding(initialValue). It returns two values: the binding object itself, and an updater function you call to push a new value into the binding.
self inside a stateful component’s init:
Using a Binding as a Prop
Pass the binding directly where you would normally pass a static value. Roact unwraps it and subscribes the property to future updates:TextButton that displays the click count. The Text property is updated in-place each time updateClickCount is called — no setState, no reconciliation.
binding:getValue()
Returns the binding’s current value synchronously.
Mapped Bindings
Often the raw binding value needs to be transformed before it can be used as an Instance property.binding:map(fn) returns a new, derived binding whose value is the result of applying fn to the upstream binding’s current value. The mapped binding updates automatically whenever the upstream does.
"Clicks: 0" initially, and updates to "Clicks: 1", "Clicks: 2", and so on without any component re-render.
Bindings created by
binding:map(fn) are read-only. Calling updateFunction on a mapped binding will throw an error. Only the original binding returned by Roact.createBinding can be updated directly.Joining Multiple Bindings
Roact.joinBindings was added in Roact 1.1.0.Roact.joinBindings(bindings). Pass it a table of bindings keyed by name; it returns a single binding whose value is a table of the same shape with each binding’s current value. Chain :map on the result to compute a final property value.
Frame to be the sum of two other frames’ sizes:
joinBindings re-fires whenever any of the upstream bindings changes, giving the :map function an up-to-date snapshot of all values.
Refs
While bindings target individual properties, refs give you access to the entire Roblox Instance that Roact created. A ref is a special binding that Roact automatically points at the underlying Instance when the component mounts and clears when it unmounts. Refs can only be attached to host components (strings like"TextBox" or "Frame"). They cannot be attached directly to stateful or function components.
Creating and Using a Ref
Create the ref in init
Call
Roact.createRef() and store the result on self. Because function components recreate their locals on every call, refs must live inside stateful components.Refs expose a
current field that maps to the same value as ref:getValue(). This field is deprecated and exists only for backwards compatibility. Prefer ref:getValue() in new code. The current field is also read-only — assigning to it will throw an error.Refs as Host Properties
Some Roblox Instance properties accept another Instance as their value —NextSelectionLeft, NextSelectionRight, NextSelectionUp, and NextSelectionDown are common examples for gamepad navigation. Because refs are bindings under the hood, Roact’s renderer knows to unwrap them automatically when they appear as property values:
Ref Forwarding
Roact.forwardRef was added in Roact 1.4.0.Roact.forwardRef:
forwardRef strips the Roact.Ref key out of the props table and passes it as a separate second argument to your render function. You can then pass it straight through to a host element.
Before forwarding — the ref is silently ignored:
TextBox:
Function Refs (Legacy)
The original ref API accepted a plain function as theRoact.Ref prop value rather than a ref object. This style still works but is not recommended for new code.