Filament.Experimental.Hooks
(filament v0.4.0)
Copy Markdown
Experimental hooks that are not yet part of the stable Filament API.
Import this module inside render/1 (or at the top of your component) to opt in:
import Filament.Experimental.HooksExperimental hooks may change or be removed in future releases.
Summary
Functions
Registers an event handler and returns a stable wire ref suitable for use as a
data-* attribute so JS hooks can route pushEvent calls directly to this fiber.
Functions
Registers an event handler and returns a stable wire ref suitable for use as a
data-* attribute so JS hooks can route pushEvent calls directly to this fiber.
The returned string (e.g. "filament:root.MyComponent[0]:0") is stable across
re-renders as long as use_event_ref/1 is called in the same order each render.
Pass it to a JS hook via a data-* attribute; the hook calls
this.pushEvent(ref, payload) and Filament dispatches directly to the handler.
import Filament.Experimental.Hooks
def render(props) do
submit_ref = use_event_ref(fn %{"text" => t} -> ... end)
~F"""
<textarea phx-hook="MyHook" data-ref={submit_ref} />
"""
endRules: call only at the top level of render/1. Do not call inside conditionals.