In live component, the parent_id is nil

I have a parent live view and a child component, and I am trying to establish a communication channel from parent to child as described in Communicating between LiveViews on the same page – The Pug Automatic, section Parent to child via send. So, in the child’s mount I have:

if connected?(socket) do
      send(socket.parent_pid, {:child_pid, self()})

However, I am getting an error message:

** (ArgumentError) argument error
    :erlang.send(nil, {:child_pid, #PID<0.679.0>})

On inspection of the socket, it appears that the parent_pid is nil in the socket in this this component.
How is that possible?

I think you’re confusing parent / child Live Views vs having just one LiveView and then it containing live components. I definitely recommend using one live view with components instead of multiple live views. For documentation on how to communicate between live components see: Phoenix.LiveComponent — Phoenix LiveView v0.15.5

1 Like

Ah yes, I am mixing things up.
I know the doc, but as that was not working (see my other topic on which you have just commented, Stateful live component is mounted more than once) I started to try other things. But I see this is the wrong way, thanks!