Phoenix.LiveComponent render from html.heex file instead of the render function?

Is it possible to render a Phoenix.LiveComponent from an html.heex file instead of the render function?

I want to maintain the html in a .heex file instead of an .ex file like I can with use AppWeb, :live_view

Only where the heex file is rendered when there is a LiveView parent. You may have a nested chain of say functional or LiveComponents and Heex templates but there must always be a parent LiveView as it is the LiveView process that manages the state for LiveComponents.

You can’t for example use a LiveComponent from a controller / dead view because there is no process to hold the component state between requests.

This is explained in the LiveComponent documentation.

2 Likes