Post

If you're learning #ElixirLang and/or #PhoenixFramework and have any questions or need help, hit me up please 🤝

I have a question 😅 I built a silly quiz app for my daughter. When you open the quiz page, there‘s an error flash message and I don‘t understand why. Here‘s the code: github.com/HerrBertling... - can you by chance spot something? This all looks at least okay to me 🤷🏼‍♂️🫠

github.comai-quiz/lib/menas_quiz_web/live/question_live/index.ex at main · HerrBertling/ai-quizAn AI Quiz app. Contribute to HerrBertling/ai-quiz development by creating an account on GitHub.

I’m not in front of my computer at the moment, but based on your description my guess is it has to do with the LiveView lifecycle. `mount/3` is called twice in that lifecycle, first when the initial static page is rendered, and again when the websocket connection is established to the page. (1/4)

Assigning and reassigning attributes how you’re currently is not very idiomatic. You’ll want to either: 1) check the socket connection status in `mount/3` and branch the assignment logic depending on if the liveview is connected or disconnected (2/4)

2) handle some assignment in the `handle_params/3` callback if it needs to run once and has branching logic depending on the url params present (3/4)

0 reposts2 likes

Ah, of course 🤦‍♂️ I thought about `assign_async` and pending UI anyways. Will check it out, the ChatGPT API takes some time to respond 👍 Thank you so much!