Trying to understand state management
If I have a reusable component with an internal state
value = use_reactive(42)
linked to an IntSlider
and I have multiple of these components on my page, how do I then get the values of all nested slider components to e.g. use in another component?
e.g.
4 Replies
Is the recommended way to inject reactive variables into reusable components from the outer scope?
e.g.
Hi Dave,
good questions.
use_reactive
already does what you want to do, so you can remove the if (actually hooks - function prefixed with use_ - should not be conditional).
I've put together a working example that demos a few of these ideas:
Run and edit this code snippet at PyCafe
Hope this helps (btw, you can run and edit the code snippet if you click the link)Thanks @MaartenBreddels!
I'm just trying to figure out how best to structure a
solara
app and I think that aligns with what I'm envisaging - only use globals for application-wide state and otherwise inject reactive variables into the components 🤔yeah, that's a good approach. When possible, it's even better to not pass reactive variables if they do not mutate them (just pass .value)