Within a single parent live view I want to move from one component back to another via a shared parent. I need a newly set socket state to prevail. I’m using push_patch
. I thought the reload: true
option was what I needed, but adding it has no effect.
Why not put it in the query params? Since it’s a list and/or a changeset. Trying to do it causes errors.
Seems like a common enough process that I must be missing something. Also misunderstanding what the “patch” being pushed is. How can I make this work the right way?
So I add my new data to the socket. This is the workflow:
- CHILD: add new data to the socket in child component
- CHILD: redirects back to the parent component
Index
. - PARENT: Call received.
mount
is skipped and onlyhandle_params
is called - PARENT: socket is examined and new data is not present
Code
# inside CHILD component I want to switch, but it passes through the parent first, without my new data
socket = # assign the data
socket
|> assign(:existing_users, existing_users)
|> assign(:user_changeset, user_changeset)
{:noreply,
socket # go back to parent now
|> push_patch(to: Routes.user_index_path(socket, :display)}
# PARENT component - data is not persisting that I just added
def handle_params(params, _url, socket) do
IO.inspect(socket.assigns.user_changeset) -> nil
IO.inspect(socket.assigns.existing_users) -> nil
# Data from original `mount` is still available only
end
#
Note: The app is only 6 months old but it looks it’s using liveView version 17.5
Edit: If I call handle_info
on the parent component manually inside child, MyAppLive.IndexComponent.handle_info(:test, socket)
I can see the socket data is persisting. I’m surprised this doesn’t cause a circular error though. Is this a valid operation type?