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 just proposed a (maybe) possible solution here:
Let’s see what happens.
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
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)
Popular in Questions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance








