anagrius

anagrius

LiveComponent update's params always contain ALL params including non-new

I have a live_view that uses live_components to swap out the content of the page’s main content area depending on the selected item in the parent. I am having an issue where the live_component’s update/2 function’s params argument always contains ALL parameters including (what is in my world) non-new. I would expect mount/1 to be called once, and it is and update/2 to be called each time an parameter changes and only include the parameters that have changed since the last call to update.

But I see update being passed all the params every time. Am i missing something, or dont i understand what constitudes “new”?

The render in the parent looks something like this:

  @impl true
  def render(assigns) do
    selected_resource = assigns.selected_resource
    page = selected_resource && page_module(selected_resource.type, selected_resource.page)
    assigns = assign(assigns, :page, page)

    ~H"""
    <div class="flex h-screen w-screen bg-green">
      <.side_menu
        project={@project}
        selected_tab={@selected_tab}
        search_active={@search_active}
        selected_resource={@selected_resource}
      />
      <div class="flex-1">
        <.async_result :let={resource} assign={@resource}>
          <:loading>
            Loading...
          </:loading>
          <:failed>
            Failed to fetch resource
          </:failed>

          <.live_component
            :if={@page}
            id="page"
            module={@page}
            resource={resource}
            resource_id={@selected_resource}
            project_id={@project_id}
            current_user={@current_user}
            timezone={@timezone}
          />
        </.async_result>
      </div>
    </div>
    """
  end

My live_component update function does:

Map.keys(params) #=> [:id, :resource, :current_user, :resource_id, :timezone, :project_id]

And outputs the same keys every time update is called.

Where Next?

Popular in Questions Top

marius95
Hello everyone, I try to use an Javascript Event Handler in my root.html.leex file. Therefore I created a function in the app.js file: ...
New
9mm
I am constructing a JSON object (map) and I need to conditionally set a field. I’m trying to write proper elixir-way code… and I’m at a l...
New
lastday4you
I wanted to check elixir version in phoenix because i found that my elixir is 1.5 but when i use Enum.chunk_by it said the function is un...
New
JulienCorb
I am trying to implement my new.html.eex file to create new posts on my website. new.html.eex: &lt;h1&gt;Create Post&lt;/h1&gt; &lt;%= ...
New
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
ycv005
I have followed this StackOverflow post to install the specific version of Erlang. And When I am running mix ecto.setup then getting fol...
New
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
bsollish-terakeet
Credo is smart enough to check for (something like) this: assert length(the_list) == 0 with this response: Checking if an enum is empt...
New
jason.o
In the code below, if the create action is not set to accept “extra_key” as an input, it errors out with a message shown above. Is there ...
New
svb
Hi! Currently I want to submit a form by pressing the Enter key. However, since my input field is of type “textarea” this is just adds a...
New

Other popular topics Top

Lily
In templates/appointment/index.html.eex: &lt;%= for appointment &lt;- @appointments do %&gt; &lt;tr&gt; &lt;td&gt;&lt;%= appoi...
New
hariharasudhan94
lets say i have a sample like a = 20; b = 10; if (a &gt; b) do {:ok, "a"} end if (a &lt; b) do {:ok, b} end if (a == b) do {:ok, "equa...
New
jay1
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New
aesmail
Hello guys, I have finally made it. I created an admin interface for a framework. It’s been on my todo list for years and with the curre...
New
vrod
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors: [WARN] - (starship::utils): Executing command ...
New
dblack
I’ve got an issue with an app and I’ve no idea of how to troubleshoot it. I’m hoping someone here might have seen something similar. I p...
New
romenigld
I am trying to run a deploy with docker and I successfully runned with this command: docker build -t romenigld/blog-prod . but when I t...
New
hariharasudhan94
I would like to know what is the best IDE for elixir development?
New
marick
I had some trouble figuring out how to make many-to-many associations work. Once I got it working, I wrote a blog post. Because I’m a nov...
New
lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New

We're in Beta

About us Mission Statement