Handle
Reactive controller bound to a specific UI Instance path.
Client Only
This class is only available when running on the client.
A Handle is the core primitive of Fragment. It binds a renderer function to a specific UI Instance resolved via a path from PlayerGui, and re-runs that renderer whenever its subscribed data or state changes.
Handles manage:
- Rendering and effect lifecycles
- Local reactive state slots
- Derived and memoized values
- Async state helpers
- Named signal connections
- Store and Context subscriptions
- Diffing containers for dynamic children
Render-cycle methods
These methods are only active inside a renderer or an Effect callback. Calling them outside produces a warning and does nothing.
Effect(fn, deps?)
Registers a side-effect that runs after the render. If fn returns a cleanup function, it runs before the effect's next run.
Prop
Type
deps works like derive's
With no deps, the effect tears down and reruns on every render — the original behavior. Pass a deps array (same shallow-equal comparison as derive) to skip teardown/rerun entirely when nothing in it changed, e.g. a connection that only needs re-wiring when the target Instance changes, not on every unrelated state update.
Example:
Handle.Effect(function()
local conn = RunService.Heartbeat:Connect(function()
element.Text = os.date("%H:%M:%S")
end)
return function()
conn:Disconnect()
end
end) -- no deps: reconnects every render
Handle.Effect(function()
print("target changed:", targetId())
end, { targetId() }) -- -- skips teardown/rerun while targetId() is unchangedAction(actionName, fn)
Registers a named action callable from outside the renderer via the handle.
Prop
Type
Example:
Handle.Action("Toggle", function(state: boolean)
element.Visible = state
end)
-- From anywhere:
Fragment.getHandle("Shop"):Toggle(true)Once(fn)
Runs fn exactly once on the first render.
Prop
Type
Example:
Handle.Once(function()
for index, mutation in ipairs(MutationsAndRarity.Mutations) do
table.insert(tabs, { Name = mutation.Name, Tier = index })
end
end)Connect(connName, signal, callback)
Binds a named connection slot to an RBXScriptSignal.
Prop
Type
Example:
local closeBtn = element.TopFrame.Close :: TextButton
Handle.Connect("Close", closeBtn.Activated, function()
Fragment.getHandle("Shop"):Toggle(false)
end)RegisterContainer(frame)
Returns a persistent Container for frame that diffs children across renders.
Prop
Type
Available inside Effects
RegisterContainer can be called both at the top level of a renderer and inside Effect callbacks.
Example:
local list = Handle.RegisterContainer(element.ScrollFrame)
for i, entry in ipairs(data.entries) do
local row = Fragment.useComponent("LeaderboardRow", { name = entry.name, score = entry.score })
list.UpsertChild(entry.id, row)
endBindings
Bindings are slots that persist across renders. They must be called in the same order on every render.
handle:bind(initialValue)
Creates a reactive state slot inside the renderer. The slot is initialised once on the first render.
Prop
Type
Returns:
- getter:
() -> any— reads the current value - setter:
(any) -> ()— updates the value and queues a re-render
Example:
local tabIndex, setTabIndex = Handle:bind(1)
for i, tab in ipairs(tabs) do
local live = container.UpsertChild(tab.name, Assets.Tab:Clone())
live.Active = tabIndex() == i
Handle.Connect("Tab_" .. tab.name, live.Activated, function()
setTabIndex(i)
end)
endBatched
Calling several setters in the same tick — two bind setters, a store update and a context patch, anything — produces exactly one render, not one per call. Fragment coalesces them the same way React 18's automatic batching does.
handle:spring(initialValue, config?)
Creates a value that animates toward whatever target the setter is given, using damped spring physics instead of jumping straight there — the same idea as Fusion's Spring. The getter keeps changing on its own (via a shared RunService.Heartbeat) until it settles on the target.
Prop
Type
frequency— oscillations per second if undamped (default4)damping—1= critically damped,< 1= bouncy,> 1= sluggish (default1)
Supported types
number, Vector2, Vector3 and UDim2 animate correctly (UDim2 is decomposed into its four scalar components, since it has no scalar multiplication). Any other type — Color3, which Roblox gives no arithmetic operators at all — can't be integrated this way and just snaps straight to the target.
Example:
local size, setSize = Handle:spring(UDim2.fromOffset(100, 40), { frequency = 4, damping = 1 })
Handle.Connect("Hover", element.MouseEnter, function()
setSize(UDim2.fromOffset(120, 48))
end)
Handle.Connect("Unhover", element.MouseLeave, function()
setSize(UDim2.fromOffset(100, 40))
end)
element.Size = size()handle:derive(fn, deps)
Returns a getter whose value is recomputed only when deps changes.
Prop
Type
Example:
local getFiltered = Handle:derive(function()
return superDuperTableFilterFunction(allItems, function(item)
return item.tier == currentTier
end)
end, { currentTier })
for _, item in ipairs(getFiltered()) do
-- render item
endhandle:hold(fn, deps)
Returns a stable function reference. The same function object is returned as long as deps is unchanged.
Prop
Type
Example:
local onBuy = Handle:hold(function()
purchaseItem(selectedItem())
end, { selectedItem() })
Handle.Connect("BuyBtn", buyButton.Activated, onBuy)handle:await(fn, deps?)
Runs fn asynchronously and returns a status table. Triggers a re-render when the operation settles.
Non-blocking
await uses task.spawn internally and never yields the renderer. The renderer immediately receives a "pending" status table and re-renders again once the operation resolves.
Prop
Type
status is one of:
"pending"— operation in progress"resolved"— completed successfully,valueholds the result"rejected"— failed,errorholds the message
Example:
local inventory = Handle:await(function()
return InventoryService:FetchAsync()
end, { store.lastUpdated })
if inventory.status == "pending" then
element.Spinner.Visible = true
return
end
element.Spinner.Visible = false
if inventory.status == "resolved" then
for _, item in ipairs(inventory.value) do
-- render item
end
endhandle:pull(ctx)
Subscribes the handle to a Context and returns the live value table.
Prop
Type
Example:
local win = Handle:pull(WindowContext)
element.Visible = win.active == "Shop"handle:attribute(instance, attributeName)
Subscribes to a replicated Instance Attribute and returns a getter for its current value. Whatever sets it — a server script via instance:SetAttribute, ReplicaService, Knit, a plain RemoteEvent handler — shows up here reactively, through Roblox's own attribute replication, without Fragment depending on any particular networking library.
Prop
Type
Fixed on first call, like bind
The (instance, attributeName) pair is fixed the first time this slot is called — calling it again with a different instance/name on a later render does not re-subscribe.
Example:
local getCoins = Handle:attribute(player, "Coins")
element.Text = `Coins: {getCoins()}`Other methods
Disconnect(connName)
Manually disconnects a named connection outside of a render.
Prop
Type
Example:
Handle:Disconnect("Close")Render()
Manually triggers a full render pass.
Prop
Type
Example:
Fragment.getHandle("HUD"):Render()Unmount()
Tears a handle down for good: runs every effect cleanup, disconnects every Connect/visibility/attribute connection, removes it from every store and context it subscribed to via useStore/pull, and cancels any spring still animating on it. Idempotent — safe to call more than once.
Prop
Type
Mostly for Fragment.mount
newHandle-created handles are meant to live for the whole session and never need this. It exists for handles that come and go on their own — Fragment.mount is the main one.
Example:
local handle = Fragment.mount(container, renderer)
-- later, when the preview/tooltip/whatever goes away
handle:Unmount()