Gilou06

Gilou06

Hello,
I wonder if is is feasible to render the same LiveComponent instance in two locations within a LiveView.
The typical case would be a LiveComponent in charge of a state, I would need to display and modify some fields in one HTML location of the LiveView, and the other fields somewhere else (HTML location).
Or, in other words: LiveComponent manages state data= %{a: one, b: two, c: :three}, I need to have a form about a at the top of the LiveView HTML page, a form about b and c at the bottom of the LiveView HTML page.
Of course, the LiveComponent would process the DB access for data as a whole.
That would require calling the LiveComponent twice within the LV, with same id and a way to select a different render function.
Is this crazy thinking ?
Thank you

Showing Posts 1 to 10

LostKobrakai

LostKobrakai

You cannot have the same LC using the same id multiple times. The whole reason there’s an id is that it uniquely identifies the LC. The also cannot share their state. But it sounds like what you’re looking for could be done without those two things anyways. Have a LC to handle the form – pass in a, b, c individually.

Gilou06

Gilou06 OP

Hi,
Ok, but I actually need two forms, one for a, one for b&c since those two forms are going to be displayed in separate location of the rendered calling LiveView.
So two forms coded in the same LC but displayed in separate LV locations. Seems impossible.

LostKobrakai

LostKobrakai

Why have the two separate forms be handled by one LC though?

Gilou06

Gilou06 OP

I wanted to regroup within the same LiveComponent forms and database code related to the same data.
That way, the forms & its events are processed within the same LC.
How would you do it : define the forms in the parent LV and send the events to the LC state manager ?

LostKobrakai

LostKobrakai

The parent LV (or LC) is the only thing containing all parts. If you really want one piece handling everything it should be that parent. Having a single state handling component (process for LV or LC) handle multiple distinct parts of the markup would make things confusing at best imo.

Gilou06

Gilou06 OP

I feel you.
Initially everything was located in the same form and I was happy like a puppy. Then for UI reasons I had to move one of the fields away (HTML wise) from his brothers. And what appeared like a simple graphic change lead to a (possibly) massive change in the code.
My thinking : it would be great to have local state management (LC takes care of changesets, DB…) but spread UI rendering : where things are in the HTML finale page.
But this is the web, not a local app…

LostKobrakai

LostKobrakai

You’re free to move business logic to a shared/common place outside of LV/LC implementations. But the LV/LC modules themselves are tightly linked to markup and its hierarchical tree structure.

Gilou06

Gilou06 OP

I’m not arguing here but I’m rather in a learner position.
My business logic is already in a dedicated module.
Then let me rephrase with what I learned from you. : What I’m trying to do is to have the state common to two LiveComponents.
That would require some communication between the module in charge of the common state (a genserver) and the LCs in charge of the markup.

  • Form in charge of “a” located in LC “A”
  • Form in charge of “b” and “c” located in LC “BC”
  • common state for %{a,b,c} in a dedicated Elixir genserver. Genserver performs send_updates to “A” and “BC”
  • “A” and “BC” call genserver API when they need to update state
    Or some pubsub instead of send_update
LostKobrakai

LostKobrakai

To me it’s still a bit unclear though why you need a, b, c to be handled together. I generally consider forms to be “low level crud’ish operations”, which might or might not line up with higher level business logic. If they don’t line up you likely want to handle the low level stuff separately from the high level stuff.

Gilou06

Gilou06 OP

I’ll review the code in light of your statement.

Where Next? Top

Trending in Questions Top

katta
I having some trouble figuring out if I have set myself too strict of standards for my production server. Currently I can handle 75% of r...
New
brecabral
Documentation While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
achenet
Hello, I’m trying to build a basic Phoenix web-app, and I’d like to use Tailwind. However, when I launch mix phx.server, I get an error...
New
kpanic
Hi everyone, I am toying with the idea of building a “match maker” for giving personal help to people that wants to start coding. I sta...
New
velrest
So my question is quite simple and i have found no conclusive answer on forum, google or AI. Should we use :erlang.float for Integer to ...
New
asweet-confluent
I recently noticed that Elixir’s Logger defaults its primary log level to :debug when no :logger, :level application configuration is pre...
New
mnkhod
So i have been using ash framework for a while and i love it. However currently the issue im having with ash framework is the error handl...
New

Other Trending Topics Top

GenericJam
Edit: 2026 May 15 - This post is archived. Mob is alive!! Main docs: mob v0.7.11 — Documentation A bit of explanation for the slightly c...
New
JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
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
mhanberg
Hi everyone! The first release candidate for the Expert language server project is now available! We’ve published a press release detai...
New
budgie
A little off-topic, but I feel like people here have a good head on their shoulders. I used to be quite good at making software. Was luc...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews