What i did
I have a module called MyAppWeb.TestComponent that is defined like this
use MyAppWeb, :live_component
def test_component(assigns) do
~H"""
<.live_component module={__MODULE__} {assigns} />
"""
end
def render(assigns) do
~H"""
<div phx-click="test_event">Test</div>
"""
end
... other stuff
I want the function test_component do be defined automatically in the MyAppWeb module
This is what i did
defmacro __using__(:live_component) do
function_name =
__CALLER__.module
|> Atom.to_string()
|> String.split(".")
|> List.last()
|> Macro.underscore()
|> String.to_atom()
quote location: :keep do
use Phoenix.LiveComponent
unquote(helpers_verified_routes())
unquote(helpers_html())
unquote(helpers_elements())
import Thimble.Phoenix.LiveHelpers
def unquote(function_name)(assigns) do
unquote(~H"""
<.live_component module={#{__CALLER__.module}} {#{assigns}} />
""")
end
end
end
The problems
I have two main problems:
- sigil_H/2 is not defined
- the last assigns is not defined
Any ideas of how can i make this work? This would come in handy to use live_components with the same syntax as the normal components allowing for better consistency






















