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
Attempting to call the create method on a ComponentState inside of a foreach call results in a ReferenceError on the frontend (only if the ComponentState has any reference to cls in the returned component).
To Reproduce
Steps to reproduce the behavior:
importreflexasrxfromreflex_test.templatesimporttemplateclassComp(rx.ComponentState):
value: int=0@classmethoddefget_component(cls, v, *children, **props) ->"Component":
returnrx.card(
rx.text(f"I'm a component with state {v}"), # <<< This alone worksrx.text(f"I'm a component with state {cls.value}"), # <<< Adding this causes error
)
@template(route='/component_state_in_foreach_issue', title='Component State in Foreach Issue')defindex() ->rx.Component:
returnrx.container(
rx.foreach(
[1, 2, 3],
Comp.create,
),
)
Expected behavior
Expect 3 separate components to be created without error.
Screenshots
If applicable, add screenshots to help explain your problem.
Specifics (please complete the following information):
Python Version: 3.12
Reflex Version: 4.9
OS: WSL2
Browser (Optional): Chrome
I think I will fall back to using a state that stores a list of an rx.Base subclass that holds the state for each item and just include the index in any calls back to event handlers so that I can update the appropriate item.
The text was updated successfully, but these errors were encountered:
Yea, I think that probably is a good solution, at least in the short term. I'm not sure if the State attribute on the rx.Component is exclusively for the rx.ComponentStatates, but if so, then just checking for components with that set inside the foreach would be enough.
Describe the bug
Attempting to call the
create
method on aComponentState
inside of aforeach
call results in aReferenceError
on the frontend (only if the ComponentState has any reference tocls
in the returned component).To Reproduce
Steps to reproduce the behavior:
Expected behavior
Expect 3 separate components to be created without error.
Screenshots
If applicable, add screenshots to help explain your problem.
Specifics (please complete the following information):
I think I will fall back to using a state that stores a list of an
rx.Base
subclass that holds the state for each item and just include the index in any calls back to event handlers so that I can update the appropriate item.The text was updated successfully, but these errors were encountered: