defmodule HelloComponent do
use Phoenix.Component
def greet(assigns) do
~H"""
<p>Hello</p>
"""
end
end
defmodule MyAppWeb.HelloLive do
use MyAppWeb, :live_view
import HelloComponent
def mount(_params, _session, socket) do
{:ok, socket}
end
def handle_event("hello", _, socket) do
IO.puts("HelloComponent injected")
{:noreply, socket}
end
def render(assigns) do
~H"""
<button phx-click="hello">+</button>
<%# Inject another HelloComponent here each time button is pressed%>
"""
end
end
After pressing the button 3 times, the webpage would look something like:
+
Hello
Hello
Hello
How can I accomplish this? I am not sure if the handle_event
is the correct way to go about it.