You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
When the value prop is not provided, the default generateUUID() is used, which generates a new unique identifier. The problem arises when the component has to re-render: the value is also re-generated. If opening the accordion item triggers some update that causes the item to re-render then it basically cannot stay open because the open state is tied to the value.
To Reproduce
importreflexasrxclassState(rx.State):
"""The app state."""sindex: int=0defindex() ->rx.Component:
# Welcome Page (Index)returnrx.container(
rx.color_mode.button(position="top-right"),
rx.vstack(
rx.heading("Welcome to Reflex!", size="9"),
rx.accordion.root(
rx.accordion.item(
header="Default value, cannot stay open",
content=f"When this component re-renders it gets a new value which is not considered open.",
on_click=State.set_sindex(0),
style={"--foo": State.sindex},
# value="1",
),
rx.accordion.item(
header="Explicit value, stays open fine",
content=f"Even when this component has to re-render it stays open because value is constant.",
on_click=State.set_sindex(1),
style={"--foo": State.sindex},
value="2",
),
width="300px",
),
spacing="5",
justify="center",
min_height="85vh",
),
rx.logo(),
)
app=rx.App()
app.add_page(index)
Expected behavior
The accordion item's open state is not reset when re-rendering the component (due to style change or otherwise).
Screenshots
If applicable, add screenshots to help explain your problem.
Specifics (please complete the following information):
masenf
changed the title
Accordion Item that depends on state var does not stay open unless value prop is set.
[REF-3375] Accordion Item that depends on state var does not stay open unless value prop is set.
Jul 25, 2024
When using rx.vars.get_uuid_string_var, wrap the prop Var in `useMemo` so that
the value remains consistent across re-renders of the component.
Fix#3707
Describe the bug
When the
value
prop is not provided, the defaultgenerateUUID()
is used, which generates a new unique identifier. The problem arises when the component has to re-render: the value is also re-generated. If opening the accordion item triggers some update that causes the item to re-render then it basically cannot stay open because the open state is tied to thevalue
.To Reproduce
Expected behavior
The accordion item's open state is not reset when re-rendering the component (due to style change or otherwise).
Screenshots
If applicable, add screenshots to help explain your problem.
Specifics (please complete the following information):
REF-3375
The text was updated successfully, but these errors were encountered: