LiveComponent and phx-target repetitiveness


In my stateful live component I have a few buttons and links that all trigger events defined in the component itself via phx-click. Things blow up (with handle_event/3 is undefined or private) if I don’t specify phx-target on them.

Specifying the target explicitly every time feels a little repetitive. Hence my question: Do I have to specify the phx-target (myself) on every click element or is there a simpler way? I am thinking if it’s possible to set phx-target on the live component itself, kind of catch-all global phx-target defined on the component’s wrapper div.

You can use surface, which does this by default. Or you can put all handle_event/3 on the LV side.

1 Like