Roact manages Roblox Instance event connections as a first-class part of the rendering process. Rather than callingDocumentation 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.
:Connect and storing RBXScriptConnection objects yourself, you declare event handlers directly inside your element’s props table. Roact connects them when the component mounts and disconnects them automatically when the component unmounts.
Connecting to Instance Events with Roact.Event
To listen to a Roblox event, add a prop whose key isRoact.Event.EVENT_NAME and whose value is the callback function you want called when the event fires.
Roact.Event uses Lua’s index metamethod, so Roact.Event.MouseButton1Click evaluates to a special marker value that Roact recognises as an event key. You can use any valid Roblox event name this way — Activated, MouseEnter, TouchTap, and so on.
Callback Signature
Roact always passes the Instance that fired the event as the first argument to your callback. Any additional arguments that Roblox provides for that event follow after.Example: ImageButton Click Handler
Automatic Disconnection
Events declared viaRoact.Event are disconnected automatically when the component unmounts. You never need to store connection objects or call :Disconnect manually — Roact handles the entire connection lifecycle for you.
Listening to Property Changes with Roact.Change
Roblox Instances exposeGetPropertyChangedSignal, which fires whenever a specific property changes. Roact provides a parallel API for this through Roact.Change.
Add a prop whose key is Roact.Change.PROPERTY_NAME and whose value is a callback. The callback receives the Instance as its first argument, just like Roact.Event callbacks.
Roact.Change.AbsoluteSize is equivalent to calling frame:GetPropertyChangedSignal("AbsoluteSize"):Connect(...) manually, but is handled declaratively and automatically cleaned up on unmount.
Example: Tracking a ScrollingFrame’s Position
Updating State from Event Handlers
A common pattern is callingself:setState inside an event handler to update a stateful component when the user interacts with the UI:
Summary
Roact.Event.EVENT_NAME
Connects to a Roblox Instance event. Callback receives
(rbx, ...) where rbx is the Instance and ... are the event’s extra arguments.Roact.Change.PROPERTY_NAME
Connects to
GetPropertyChangedSignal. Callback receives (rbx) — the Instance whose property changed.Roact.Event and Roact.Change connections are established on mount and torn down on unmount automatically. Declare them in your props table exactly like any other property.