mortenlund

mortenlund

LiveView - LiveComponent - mount - get parent assigns

Hi!

To make it easier to develop LiveComponents that require information from the current context of the LiveView it would be awesome if the LiveComponent.mount/1 could receive the assigns from the LiveView that contains the component.

A real-world example is the need to get the current_user that one may store in the assigns of the LiveView
Alternative could be to add a second mount/2 where the second argument is the parent socket or assigns

I know that you can give this as arguments when using <.live_component module={MyLiveComponent} id="myid" current_user={@current_user} /> and this will be params to the update/2 function in the component.

But sometimes you would like to load some assigns in the component only once and not everytime the page has updates that then triggers the update/2 function in the component

First Post!

LostKobrakai

LostKobrakai

You can compare what is stored in socket.assigns with the data privided by the assigns parameter of update/2 to figure out if you want to rerun some calculation or not.

Last Post!

mortenlund

mortenlund

Yes this is what I currently do :slight_smile:
Would just be intuitive if you could think of mount as “setup” function and then only supply contextual changes to the component using the update function :slight_smile:

Where Next?

Popular in Proposals: Ideas Top

derekkraan
I have been using a multi-endpoint setup in my app, just because I think it makes the most sense for a multi-subdomain app. This worked w...
New
sevensidedmarble
All the pieces are there to execute arbitrary JS commands from the server. You can put them on a data property and call them from the cli...
New
munksgaard
I’m copying and pasting this issue from @Terbium-135 here verbatim, because I would be interested in such a feature as well, and because ...
New
dkuku
This is a proposal to make the map key mismatch errors a bit better: Every time I have a typo It’s very challenging for me even when I u...
New
Oliver
One common problem we face in constructing lists is that there is (AFAIK) no support for conditionally inserting members into list declar...
New
Astolfo
When generating a release with phx.gen.release --docker a debian version is used by default to avoid “DNS issues” on Alpine. It seems li...
New
eagle-head
Hi everyone, I’ve been researching Content Security Policy Level 3 support in Phoenix and wanted to share my findings and a proposal for...
New

Other popular topics Top

vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New
JakeBecker
TL;DR: I’ve just released an implementation of Microsoft’s IDE-independent Language Server Protocol for Elixir. It adds language support ...
1144 55125 245
New
gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
New
AstonJ
Seen any cool LiveView demos, sample apps or examples? Please post them here! :003:
New
Patoshizzle
After calling mix ecto.create I get this error: 17:00:32.162 [error] GenServer #PID&lt;0.412.0&gt; terminating ** (Postgrex.Error) FATAL...
New
TunkShif
This post is an instruction guide to help you setup your Neovim for Elixir development from scratch. It includes general information on h...
274 42716 114
New

We're in Beta

About us Mission Statement