How to pass parameters to a live_render in a render() in a live_view

I am using the ThermostatLive in a :live_view.
In the render() I have a heex template with the ThermostatLive example, which displays fine.
I update the assigns and it shows it in the assigns.

@impl true
def render(assigns) do
assigns =
|> assign(test: “tgest”)
|> IO.inspect(label: :render_assigns)

<%= live_render(@socket, ThermostatLive, id: :child2) %>

However, when I IO.inspect(socket, label: :debugger, structs: false)
I don’t see the value passed in.

All I see is:

assigns: %{changed: %{}, flash: %{}, live_action: nil},


To add something to the socket, it would look something like assign(socket, :test, "test"). The absence of a socket param in the render callback indicates it’s not a good place to be updating the socket. I’d suggest taking a look at the overall LiveComponent lifecycle, and especially the mount or update callbacks instead.

Check out the Pitfalls section of the Assigns and HEEx templates guide. It explains why the render function isn’t the place to be defining variables and assigning things.

do not define variables at the top of your render function:

def render(assigns) do
  sum = assigns.x + assigns.y

  <%= sum %>

Instead explicitly precompute the assign in your LiveView, outside of render:

assign(socket, sum: socket.assigns.x + socket.assigns.y)