import solara
set_fail = None
clear = None
@solara.component
def UnstableComponent(number: int):
if number == 3:
raise Exception("I do not like 3")
return solara.Text(f"You picked {number}")
@solara.component
def Page():
value, set_value = solara.use_state(1)
value_previous = solara.use_previous(value)
exception, clear_exception = solara.use_exception()
print(exception)
if exception:
def reset():
set_value(value_previous)
clear_exception()
# bug in reacton, can not be a function component, only a widget component
with solara.v.Container():
solara.Text("Should show this")
solara.Text("Exception: " + str(exception))
solara.Button(label="Go to previous state", on_click=reset)
else:
with solara.Column(margin=12):
solara.IntSlider(value=value, min=0, max=10, on_value=set_value, label="Pick a number, except 3")
UnstableComponent(value)