peter-de-boer
I have a stateful live component. Besides the id, it receives another parameter, “products”, from the parent live view.
The parent live view constains a pubsub subscription and an handle_info that changes the products parameter.
Always when products is changed, the live component is re-rendered (as expected), and re-mounted which is not as expected.
The documentation says, a.o. “In stateful components, mount/1 is called only once, when the component is first rendered. For each rendering, the optional preload/1 and update/2 callbacks are called before render/1.”
So, I would expect that update is called with the new products, parameter. But it appears that also mount is called. What am I missing?
Trending in Questions
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
Hello,
I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
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
Documentation
While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
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
I recently noticed that Elixir’s Logger defaults its primary log level to :debug when no :logger, :level application configuration is pre...
New
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
Other Trending Topics
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
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
Hi there! We created Gust: A task orchestrator inspired by Airflow.
For those who have never heard about Aiflow, it’s a Python-based wor...
New
Hi everyone!
The first release candidate for the Expert language server project is now available!
We’ve published a press release detai...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixirconf-us
- #ai
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #hex
- #security










Showing Posts 1 to 7- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
benwilson512
Hi @peter-de-boer, one explanation is that your live component is not actually stateful. Can you supply some code showing how you’re using it / setting it up?
peter-de-boer
My component:
The component is called in the live view template:
In the live view I handle a pubsub notification:
Always when this handle_info is executed, the CartComponent is mounted.
derek-zhou
You updated one of the parameters,
cart_products, so t has to be remounted. If you don’t want the remount, you have to send whatever thing you want to change viasend_updatepeter-de-boer
Thanks, I will try that. I guess I just do not understand the documentation as it seems to suggest that these kind of updates are handled by the update function.
benwilson512
This is your issue. This will generate a new UUID on every parent render which basically means you are unmounting the old component and remounting a new component on every render. Impure functions should generally be avoided in the EEX templating calls.
derek-zhou
I’d even suggest you to avoid using stateful component until you are very comfortable with state-less components. Remember there is nothing you cannot do with a live view and a bunch of stateless component. Stateful component is only a feature to improve code organization; and you can improve code organization in other ways.
peter-de-boer
Awesome, that’s it!
(And I thought I was clever by generating some random id…)