What does "A slot entry must be a direct child of a component" mean?

Hi!

I can’t wrap my head around the functional components and how they work in Phoenix, and I can’t get past the following error.

invalid slot entry <:user_info>. A slot entry must be a direct child of a component

Any help is appreciated to help me understand what it means and how to resolve it. I thought having user_info inside the user_list would make it a direct child of a component. Here’s the test code I have,

defmodule ExampleWeb.UserComponents do
  use Phoenix.Component

  attr :username, :string, required: true

  def user_info(assigns) do
    ~H"""
    <div class="flex items-center">
      <h4><%= @username %></h4>
      etc
    </div>
    """
  end

  def user_list(assigns) do
    ~H"""
    <div>
      <:user_info username="foo" />
    </div>
    """
  end
end

Thank you!

You should have written .user_info. :user_info is the slot syntax.

2 Likes