From 627d4524d173ab053ab2d6578c89a554bbbcf3f5 Mon Sep 17 00:00:00 2001 From: Pierre Cavin Date: Thu, 9 Nov 2023 02:06:34 +0100 Subject: [PATCH] Add required option to attr/3 in Components guide (#5617) --- guides/components.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/guides/components.md b/guides/components.md index e6431b9b90..b667969bef 100644 --- a/guides/components.md +++ b/guides/components.md @@ -42,7 +42,7 @@ defmodule HelloWeb.HelloHTML do embed_templates "hello_html/*" - attr :messenger, :string + attr :messenger, :string, required: true def greet(assigns) do ~H""" @@ -52,7 +52,7 @@ defmodule HelloWeb.HelloHTML do end ``` -We declared the attributes we accept via `attr` provided by `Phoenix.Component`, then we defined our `greet/1` function which returns the HEEx template. +We declared the attributes we accept via the `attr/3` macro provided by `Phoenix.Component`, then we defined our `greet/1` function which returns the HEEx template. Next we need to update `show.html.heex`: @@ -68,7 +68,7 @@ Since templates are embedded inside the `HelloHTML` module, we were able to invo If the component was defined elsewhere, we can also type ``. -By declaring attributes, Phoenix will warn if we call the `<.greet />` component without passing attributes. If an attribute is optional, you can specify the `:default` option with a value: +By declaring attributes as required, Phoenix will warn at compile time if we call the `<.greet />` component without passing attributes. If an attribute is optional, you can specify the `:default` option with a value: ``` attr :messenger, :string, default: nil