Przeglądaj źródła

component: do not create ref for dynamic id (#1307)

allow dynamic id (BaseVar) to be specified (from state value or foreach), but
do not create a react reference for it, since that must be known at compile
time.

if a react ref is needed, then specify a string _at compile time_, not from
state.

fix #1302
Masen Furer 1 rok temu
rodzic
commit
333e2b3184
1 zmienionych plików z 2 dodań i 1 usunięć
  1. 2 1
      reflex/components/component.py

+ 2 - 1
reflex/components/component.py

@@ -553,7 +553,8 @@ class Component(Base, ABC):
         Returns:
         Returns:
             The ref name.
             The ref name.
         """
         """
-        if self.id is None:
+        # do not create a ref if the id is dynamic or unspecified
+        if self.id is None or isinstance(self.id, BaseVar):
             return None
             return None
         return format.format_ref(self.id)
         return format.format_ref(self.id)