trentjones21

trentjones21

I have multiple LiveView pages (live routes) that all need to render a child LiveView (a date picker for filtering data by date range). I want this child LiveView to be able to use live_redirect in order to change the query params in the url when it is interacted with. However, I’m getting an error saying you can’t use live_redirect in a child rendered LiveView.

I’m pretty new to Elixir, and I can’t find a lot of information on how to accomplish this. I’ve seen other threads saying to use pubsub, but it seems like that is going to lead to a lot of duplicate code as each “parent” component is going to have to subscribe to messages from the child (at least that is my understanding).

Aniy tips on how I can use live_redirect when something happens in a child rendered LiveView?

Showing Posts 1 to 2

josevalim

josevalim

Creator of Elixir

You have to message the parent because the URL is a “single resource”, and if you have two things trying to change it in incompatible ways, your application goes into an inconsistent state.

It doesn’t know to be “use pubsub”, you could do it like:

send(socket.root_pid, {:redirect_to, Routes.foo_bar(...)})

And then handling it in your parent handle_info, but in a nutshell, you should double think if this approach is correct. In particular, double think if you really need two live views (especially with the components features in master - although you will need to check the source to read the docs).

trentjones21

trentjones21 OP

Thank you for the response. It was really helpful.

I realized my mistake. In case anyone ends up here with the same problem I had – I was treating live views much like one would treat react components. However, it occurred to me after reading Jose’s response that I could make a regular .eex component rather than using a live view to accomplish what I was trying to do. I ended up following this tutorial and got things working how I needed them, without having to use a child live view.

— All posts loaded —

Where Next? Top

Trending in Questions Top

stjefim
Hello! Suppose you are building workflow (order / task / payment) processing system with the following requirements: Each workflow con...
New
water
I’m aware of 2 such projects, are there others? git: GitHub - team-alembic/realworld: A fullstack Phoenix LiveView application with back...
New
itzmidinesh
Hi all, I’m working on a Phoenix project where I need to make external HTTP requests and I’m trying to choose between Req and HTTPoison....
New
peck
Hi everyone. My team and I have been working on a fairly modest app based around video streaming and chat, but we’ve landed a customer t...
New
leoschweizer
Hi, we run different LLM models across a cluster, with each node loading a configurable subset. Model-specific queues let nodes consume ...
New
csmr
Hi all, I’m new here and would like to hear peoples views on my Elixir/Phoenix based game-engine! :smiley: Mutonex gamedesign was finish...
New
perzanko
Do we have maintainer of absinthe-graphql/dataloader here? We have a PR that we’d like to merge to the library. Relatively small additive...
New

Other Trending Topics Top

dominicletz
Hey there, I haven’t seen a list of useful Elixir specific skills for the popular AI tools yet so I’m starting one here with my first. ...
New
mudasobwa
I fully migrated to my own harness from Anthropic/Gemini and I think it’s time to share it. Welcome DSH, the DeepSeek Harness, fully writ...
New
KristerV
Hey. Is there anyone here who creates agents in their apps? Not talking about using agents, but creating them. I’m finding it pretty diff...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
webofbits
With AI doing more of the implementation work, I’ve been wondering how much coding I should deliberately keep doing myself. My main conc...
#ai
New
OndrejValenta
(I just needed to vent somewhere and LinkedIn is full of hope, or hype, I’m not sure which exactly) AI dream has many faces, but general...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews