You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
false or nil - if a value is false or nil, the attribute is omitted. Some attributes may be rendered with an empty value, for optimization purposes, if it has the same effect as omitting [...]
Invoking it like this <.span class={if nil, do: nil}>Hello World</.span> also won't pick up the default value of the attr.
So, "nillish" values are handled in 3 different ways. Given that conditional logic with attrs is pretty common, should we try to make this more consistent for better DX?
Always empty attributes with nil unless it's a boolean attribute!?
Prevent compiler type checking attr when nil (unless attr is required)!?
Empty attr assign / use default value when nil is given to attr
The text was updated successfully, but these errors were encountered:
Typically
nil
andfalse
will omit the attribute as per the documentation:https://hexdocs.pm/phoenix_live_view/Phoenix.Component.html#sigil_H/2-syntax
So, the following:
Will output:
<span class="">Hello World</span>
And the following:
Will output:
<span>Hello World</span>
It gets especially weird because this is not how it's handled if you have a function component with global attributes:
The following:
Will output:
<span data-phx-id="m3-phx-GBS__HJfKXiKyBHD">Hello World</span>
I don't know exactly what optimizations the doc is referring to, but to me, it already feels too implicit/ hard to track.
And it gets a little trickier because you can bypass the compiler warning with something like the following:
Invoking it like this
<.span class={if nil, do: nil}>Hello World</.span>
also won't pick up the default value of the attr.So, "nillish" values are handled in 3 different ways. Given that conditional logic with attrs is pretty common, should we try to make this more consistent for better DX?
nil
unless it's a boolean attribute!?nil
(unless attr is required)!?nil
is given to attrThe text was updated successfully, but these errors were encountered: