Created
August 24, 2020 22:01
-
-
Save BenSchZA/060f32ab24717f3c822b9b378515ea67 to your computer and use it in GitHub Desktop.
Phoenix LiveComponent rendering error
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
** (ArgumentError) cannot convert component AppWeb.Component.Statistic with id nil to HTML. | |
A component must always be returned directly as part of a LiveView template. | |
For example, this is not allowed: | |
<%= content_tag :div do %> | |
<%= live_component @socket, SomeComponent %> | |
<% end %> | |
That's because the component is inside `content_tag`. However, this works: | |
<div> | |
<%= live_component @socket, SomeComponent %> | |
</div> | |
Components are also allowed inside Elixir's special forms, such as | |
`if`, `for`, `case`, and friends. So while this does not work: | |
<%= Enum.map(items, fn item -> %> | |
<%= live_component @socket, SomeComponent, id: item %> | |
<% end %> | |
Since the component was given to `Enum.map/2`, this does: | |
<%= for item <- items do %> | |
<%= live_component @socket, SomeComponent, id: item %> | |
<% end %> | |
(phoenix_live_view 0.11.1) lib/phoenix_live_view/engine.ex:20: Phoenix.HTML.Safe.Phoenix.LiveView.Component.to_iodata/1 | |
(phoenix_live_view 0.11.1) lib/phoenix_live_view/engine.ex:139: Phoenix.HTML.Safe.Phoenix.LiveView.Rendered.to_iodata/3 | |
(app 0.1.0) lib/app/Domain/reports.ex:42: Domain.Reports.create/2 | |
(app 0.1.0) lib/app/Domain/reports.ex:13: anonymous fn/1 in Domain.Reports.send_daily/0 | |
(elixir 1.10.4) lib/enum.ex:1396: Enum."-map/2-lists^map/1-0-"/2 | |
(app 0.1.0) lib/app/Domain/reports.ex:9: Domain.Reports.send_daily/0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment