itSQualL

itSQualL

Why LiveComponent mount/1 socket doesn't keep the assigns from liveview parent?

Hi!

We want to know why livecomponent mount/1 socket is empty. Shouldn’t be the same socket passed through when invoking it from liveview parent?

We’d like to use livecomponent mount to assign initial component state, but we need some info like current user_id.

We thought that info would be available on socket but it is empty.

We could move the logic to the preload or update methods, but then, the functions will be called in each update instead of being called only at the beginning.

So, what is the purpose of livecomponent mount if you can’t access to any contextual data?

Most Liked

i-n-g-m-a-r

i-n-g-m-a-r

I just proposed a (maybe) possible solution here:

Let’s see what happens.

i-n-g-m-a-r

i-n-g-m-a-r

Great question.
Initializing anything useful can only be done in update/2.
mount/1 needs (readonly) access to “parent” assigns to become useful.
I have spent many hours finding a solution without any success.
Please update when you find something.

i-n-g-m-a-r

i-n-g-m-a-r

you are aware that you can copy the state from parent to child (using assign) ?
(and have as many copies of the parent assigns as you have children LiveComponents)
what you can’t do is read the parent state once while mounting and translate (some of) the parent state into an independent child state.
(we would want that of course)

Where Next?

Popular in Questions Top

_russellb
I want to try my hand at web scraping. What tools/libraries do I need to use. I’m hoping to turn this into something professional so don’...
New
vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
Darmani72
If I have a post route which an argument: post /my_post_route/:my_param1, MyController.my_post_handler How would get the post params ...
New
Patoshizzle
After calling mix ecto.create I get this error: 17:00:32.162 [error] GenServer #PID<0.412.0> terminating ** (Postgrex.Error) FATAL...
New
myronmarston
The Elixir Typespec docs show the following syntax for keyword lists in typespecs: # ... | [key: type] # keyword lists...
New
JeremM34
Hello, how can I check the Phoenix version ? Thanks !
New
tduccuong
Hi, is there any work on GUI with Elixir, that is similar to Electron/Javascript? My idea is to bundle Phoenix and BEAM into a single se...
New
JulienCorb
I am trying to implement my new.html.eex file to create new posts on my website. new.html.eex: <h1>Create Post</h1> <%= ...
New
jay1
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New
Brian
What is the proper way to load a module from a file in to IEX? In the python world, doing something like this pretty standard: from ....
New

Other popular topics Top

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
chrismccord
As promised, the first release candidate of Phoenix 1.3.0 is out! This release focuses on code generators with improved project structure...
New
electic
Hi, I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
johnnyicon
Hi all, I’ve just started learning Elixir and Phoenix Framework, so please pardon my n00bness at this stage. I’m trying to use Postgres...
New
dokuzbir
I want to highlight html closing tags when i click a html tag. That works in .html files but doesnt work for html.eex templates. How can...
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
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
New
AstonJ
Please see the new poll here: Which code editor or IDE do you use? (Poll) (2022 Edition) It’s been a while since we first asked this, I...
208 31142 143
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

We're in Beta

About us Mission Statement