This is something that I banged by head against for the last two days.
My findings:
- Phoenix.Component is to be used like LiveComponent without states. Maybe it’s even more basic to consider any of those.. perhaps it’s to be used as a dumb UI atomic components.
- So if originally the LiveComponent had
handle_event
callback functions, then that is a stateful live component - which means you gotta use it still, asPhoenix.Component
is only to replace stateless components. - For any modules that
use Phoenix.Component
, you either can create a function that it expects for rendering - the 1-arity function taking inassigns
, and returning a H-sigil based in-line template. - However, if your template is too big (and I don’t think that’s the most general use case for
Phoenix.Component
. The examples are for small UI elements), then you can just pass in therender/1
function that gets added on viause Phoenix.Component
, much likeuse Phoenix.LiveComponent
. This is key. Above picture shows that.
Man I banged my head against this for so long.
And then I realized that the update/2
, handle_event/2
functions might not work.
Which led me to think… perhaps those functions are pertinent to the state-based live components that the documentation was referring to, which, in state-ful, you still need to use LiveComponent
.
Something new! Overall really excited for Phoenix 1.6 release!! Much thanks to the team.