In my liveview I have a component where I need to send the user id.
<%= live_component MyComponent, id: "foobar", current_user: @current_user %>
My question: is it cheaper to send the whole @current_user struct or should I just send the field I’m interested in.
<%= live_component MyComponent, id: "foobar", current_user: @current_user %>
# vs
<%= live_component MyComponent, id: "foobar", current_user_id: @current_user.id %>
Which one is better for performance? The official documentation is confusing me.
Therefore it is your responsibility to keep only the assigns necessary in each component. For example, avoid passing all of LiveView’s assigns when rendering a component:
<.live_component module={MyComponent} {assigns} />
Instead pass only the keys that you need:
<.live_component module={MyComponent} user={@user} org={@org} />
Luckily, because LiveViews and LiveComponents are in the same process, they share the data structure representations in memory. For example, in the code above, the view and the component will share the same copies of the
@user
and@org
assigns.
The liveview and the livecomponent use the same process and share memory but still don’t pass in structs? Appreciate some clarity, thanks!