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

1 Like

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.

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: