diff --git a/reflex/components/component.py b/reflex/components/component.py index e1a398786..6e4c6c37f 100644 --- a/reflex/components/component.py +++ b/reflex/components/component.py @@ -179,6 +179,7 @@ ComponentStyle = Dict[ Union[str, Type[BaseComponent], Callable, ComponentNamespace], Any ] ComponentChild = Union[types.PrimitiveType, Var, BaseComponent] +ComponentChildTypes = (*types.PrimitiveTypes, Var, BaseComponent) def satisfies_type_hint(obj: Any, type_hint: Any) -> bool: @@ -707,12 +708,9 @@ class Component(BaseComponent, ABC): if isinstance(child, (tuple, list)): validate_children(child) - if isinstance(child, Var): - continue - # Make sure the child is a valid type. - if isinstance(child, dict) or not types._isinstance( - child, ComponentChild + if isinstance(child, dict) or not isinstance( + child, ComponentChildTypes ): raise ChildrenTypeError(component=cls.__name__, child=child) diff --git a/reflex/utils/types.py b/reflex/utils/types.py index 6f19bb9ca..b432319e0 100644 --- a/reflex/utils/types.py +++ b/reflex/utils/types.py @@ -95,6 +95,7 @@ GenericType = Union[Type, _GenericAlias] # Valid state var types. JSONType = {str, int, float, bool} PrimitiveType = Union[int, float, bool, str, list, dict, set, tuple] +PrimitiveTypes = (int, float, bool, str, list, dict, set, tuple) StateVar = Union[PrimitiveType, Base, None] StateIterVar = Union[list, set, tuple]