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
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
You can find more information about here
Top comments (0)