Dave Hirschfeld
Dave Hirschfeld
SSolara
Created by Dave Hirschfeld on 3/17/2024 in #questions-issues
Trying to understand state management
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 🤔
6 replies
SSolara
Created by Dave Hirschfeld on 3/17/2024 in #questions-issues
Trying to understand state management
Is the recommended way to inject reactive variables into reusable components from the outer scope? e.g.
@solara.component
def SliderComponent(value: int | Reactive[int] = 0) -> None:
if not isinstance(value, Reactive):
slider_value = solara.use_reactive(value)
else:
slider_value = value
solara.IntSlider('', slider_value.value, min=0, max=50)

@solara.component
def MyApp():
slider1 = solara.use_reactive(21)
slider2 = solara.use_reactive(42)
SliderComponent(slider1)
SliderComponent(slider2)
SomeComponentThatUsesTheValuesOfAllSliders(
slider1, slider2,
)
@solara.component
def SliderComponent(value: int | Reactive[int] = 0) -> None:
if not isinstance(value, Reactive):
slider_value = solara.use_reactive(value)
else:
slider_value = value
solara.IntSlider('', slider_value.value, min=0, max=50)

@solara.component
def MyApp():
slider1 = solara.use_reactive(21)
slider2 = solara.use_reactive(42)
SliderComponent(slider1)
SliderComponent(slider2)
SomeComponentThatUsesTheValuesOfAllSliders(
slider1, slider2,
)
6 replies