All examples in documentation should work. If not then we would submit a bug report, but before that would happen just to be sure could you please share a minimal script to reproduce issue (ideally with example from documentation)?
You can use a minimal example of LiveView from here:
defmodule MyTable do
use Phoenix.LiveComponent
def render(assigns) do
~H"""
<table>
<tr>
<%= for col <- @col do %>
<th><%= col.label %></th>
<% end %>
</tr>
<%= for row <- @rows do %>
<tr>
<%= for col <- @col do %>
<td><%= render_slot(col, row) %></td>
<% end %>
</tr>
<% end %>
</table>
"""
end
end
defmodule SamplePhoenix.SampleLive do
use Phoenix.LiveView
# …
def mount(_params, _session, socket) do
users = [
%{address: "john.doe@example.com", name: "John Doe"},
%{address: "sample@example.com", name: "Sample"}
]
{:ok, assign(socket, :users, users)}
end
# …
def render(assigns) do
~H"""
<.live_component id="my-table" module={MyTable} rows={@users}>
<:col :let={user} label="Name">
<%= user.name %>
</:col>
<:col :let={user} label="Address">
<%= user.address %>
</:col>
</.live_component>
"""
end
end
The docs are quite terse but they imply that you have to make sure to pass the assign along in update/2 if you’re not doing that.
def update(assigns, socket) do
socket = assign(socket, :col, assigns.col)
# or socket = assign(socket, assigns) if you want to keep them all
{:ok, socket}
end
I’m not actually sure if you can use the slot macro for a LiveComponent, though I don’t think it’s actually required? Did you try it?