Changing the component internal state externally. #3575
Unanswered
vnermolaev
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi there!
I’m currently developing a component that maintains an internal state and re-renders itself based on that state. I’d like to use this component as a child of another component, with the ability to instruct the child to update its state and trigger a re-render.
The first solution that comes to mind is passing a signal from the parent to the child. When the signal changes, Dioxus re-renders the child component, where I can update its internal state. However, updating the internal state inside the child component triggers another re-render, creating a circular loop. Dioxus correctly reports this issue with the following warning:
I cannot really use
use_effect
because "Effects are reactive closures that run after the component has finished rendering." (see docs).I cannot use
use_memo
because it computes derived data, while I need to update my internal state.To break this cycle, my current solution is as follows:
That said, I’m curious if there’s a more established or idiomatic way to handle this scenario. Is there a best practice for solving this kind of issue in Dioxus?
Beta Was this translation helpful? Give feedback.
All reactions