Getting Started

Hello React

Render a component from a controller, with no socket

  • dead view
  • SSR

Key concepts

react/1 works in any Phoenix template, not only inside a LiveView. This page has no socket: the component is server-rendered on the first request and hydrated in the browser, and there is no websocket behind it.

page_html.ex
defmodule MyAppWeb.PageHTML do
  use MyAppWeb, :html

  def simple(assigns) do
    ~H"""
    <.react name="Simple" />
    """
  end
end

How it works

The component is rendered by a plain function component from a controller action. Use this when you want React for its own sake — a widget, a chart, a third-party library — without any server-driven state.