-
Notifications
You must be signed in to change notification settings - Fork 1
Lifecycle
github-actions[bot] edited this page Apr 3, 2026
·
2 revisions
Widgets have three lifecycle callbacks: mount, unmount and update.
Fires after a widget is added to the tree via addChild. self.parent is already set when the handler runs.
widget:onMount(function(self)
print("mounted, parent is", self.parent)
end)To override in a subclass:
function MyWidget:mount()
Widget.mount(self) -- fires registered onMount handlers
-- custom setup
endFires after a widget is removed from the tree via removeChild. self.parent is already nil when the handler runs but self.children, props, and reactive state are still intact.
widget:onUnmount(function(self)
print("unmounted")
end)To override in a subclass:
function MyWidget:unmount()
Widget.unmount(self) -- fires registered onUnmount handlers + cleans up reactive state
-- custom teardown
endFires every frame via host:update(dt). dt is delta time in seconds.
local x = 0
widget:onUpdate(function(self, dt)
x = x + 100 * dt
end)To override in a subclass:
function MyWidget:update(dt)
Widget.update(self, dt) -- fires registered onUpdate handlers + propagates to children
-- per-frame logic
endSearch lifecycle in the example browser.