mortenlund

mortenlund

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

Showing Posts 1 to 2

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.

mortenlund

mortenlund OP

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:

— All posts loaded —

Where Next? Top

Trending in Proposals: Ideas Top

woylie
We are seeing a lot of warning logs like this: navigate event to "https://someurl" failed because you are redirecting across live_sessio...
New

Other Trending Topics Top

mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
mcass19
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge &amp; Solve. They are GUI (Emerge) and State management (S...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
wintermeyer
There are three potential reasons for members of this forum to have a look at https://vutuv.de You are tired or annoyed of LinkedIn. Yo...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews