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
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.
Popular in Proposals: Ideas
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









