Use case for returning {:reply, map, socket} in handle_event callback

Reply to a an event from a hook.

https://hexdocs.pm/phoenix_live_view/js-interop.html#client-hooks

For example, in my hook in mounted()


mounted() {
  ...
  // push event to liveview after handle is moved
  this.slider.on("change", (values, handle) => {
    this.pushEvent("scroll_to_time", { mins: values[handle] }, (payload) => {
      this.slider.set(payload.mins);
    });
  });
  ...

and in my liveview:

  def handle_event("scroll_to_time", %{"mins" => mins}, socket) do
    ...
    {:reply, %{mins: mins}, socket}
  end
3 Likes