DEV Community

Luis Gustavo Caciatori
Luis Gustavo Caciatori

Posted on

TIL Phoenix Live View #1

With Phoenix LiveView 0.18 now you can define attributes to components

attr :name, :string, required: true
# or define with default value
# attr :name, :string, default: "World"

def hello(assigns) do
  ~H"""
    <h1>Hello #{@name} </h1>
  """
end
Enter fullscreen mode Exit fullscreen mode

But the most interesting part is that you can also define with a Schema or Struct, helping you with autocomplete (if your editor supports) and compile warns

attr :user, User, required: true

def hello(assigns) do
  ~H"""
    <h1>Hello #{user.name}</h1>
  """
end
Enter fullscreen mode Exit fullscreen mode

You can find more information about here

Top comments (0)