`phx-click` and JS `onclick` together

Maybe you’re looking for push_event? To call client JS from the server as in:

{:noreply, push_event(socket, "scores", %{points: 100, user: "josé"})}

You can then handle that on a LV hook or on a window.addEventListener(...) on your app.js.

The docs are pretty good if you get into them, at least that’s what I found. It took me a little bit to understand, so I wrote this up. Hopefully not adding to any confusion…

Maybe that helps? Have you also seen in the docs: handling server-pushed events and there’s also a section on custom events that you might want?

I’ve personally found that this area of LiveView has allowed me to make magical experiences with almost embarrassingly little effort.