0

In Phoenix, if you need to process the data in the template, you can pass the data to the view for processing to be outputted back to the template. For example:

## index.html.heex
<%= for a <- @articles do %>
  <%= a.title %>
  <%= get_category(a.category_id).name %>

## article_view
def get_category(id) do
  Categories.get_article_category!(id)

However, this is different with LiveView. I've tried to call a component in the comprehension to process the data:

## index.html.heex
<%= for a <- @articles do %>
  <%= a.title %>
  <%= live_component @socket, CategoryComponent, id: a.category_id %>id %>

But now, I'm lost on how to make the Category component (handle_info?) to put the Category names of each article.

What is the proper way to update the data in a rendered list in LiveView?

Adam Millerchip
  • 20,844
  • 5
  • 51
  • 74
Jun Dalisay
  • 1,165
  • 2
  • 12
  • 26

1 Answers1

0

I could't spend so much time on this so I just used the methods in the context and will put the LiveView queries there

# index.html.heex
<%= App.Categories.get_category!(a.category_id).name %>
Jun Dalisay
  • 1,165
  • 2
  • 12
  • 26