Phoenix.LiveView.Helpers.live_component
You're seeing just the macro
live_component
, go back to Phoenix.LiveView.Helpers module for more information.
Link to this macro
live_component(socket, component, assigns \\ [], do_block \\ [])
View Source (macro)Renders a Phoenix.LiveComponent
within a parent LiveView.
While LiveView
s can be nested, each LiveView starts its
own process. A LiveComponent provides similar functionality
to LiveView, except they run in the same process as the
LiveView
, with its own encapsulated state.
LiveComponent comes in two shapes, stateful and stateless.
See Phoenix.LiveComponent
for more information.
Examples
All of the assigns
given are forwarded directly to the
live_component
:
<%= live_component(@socket, MyApp.WeatherComponent, id: "thermostat", city: "Kraków") %>
Note the :id
won't necessarily be used as the DOM ID.
That's up to the component. However, note that the :id
has
a special meaning: whenever an :id
is given, the component
becomes stateful. Otherwise, :id
is always set to nil
.