LiveDelegate

LiveDelegate helps split a Phoenix LiveView into smaller, composable modules without introducing LiveComponents or changing the normal LiveView lifecycle.

defmodule MyAppWeb.DashboardLive do
use MyAppWeb, :live_view
use LiveDelegate
alias MyAppWeb.DashboardLive.Projects
delegate(:projects, Projects)
def mount(params, session, socket) do
{:ok, socket |> delegate_mount(params, session)}
end
end
defmodule MyAppWeb.DashboardLive.Projects do
use LiveDelegate, path: [:projects]
def on_mount(_params, _session, socket) do
socket |> delegate_assign(%{items: []})
end
end

LiveDelegate keeps related concerns together:

See the LiveDelegate module documentation for the complete guide.