DEV Community

Luis Gustavo Caciatori
Luis Gustavo Caciatori

Posted on

2

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)

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay