reflex-dev/reflex · error · TypeError
`children` in `{fn.__name__}` must be annotated as `rx.Var[r
Error message
`children` in `{fn.__name__}` must be annotated as `rx.Var[rx.Component]`. What it means
The reserved `children` parameter of an `@rx.memo` function must be annotated exactly as `rx.Var[rx.Component]` (a component pass-through slot). This error fires when `children` carries some other annotation that is not an event-handler annotation — such as `rx.Var[str]` or a bare type. It is raised at decoration time by `_analyze_params`.
Source
Thrown at packages/reflex-base/src/reflex_base/components/memo.py:1313
annotation = Var[Any]
else:
annotation = Var[annotation]
defaulted_params.append(parameter.name)
if is_missing and missing_params is not None:
missing_params.append(parameter.name)
# Children parameters by name must match the children kind exactly —
# otherwise we accept a value-typed `children` and emit confusing JSX.
if (
parameter.name == "children"
and not _children_annotation_is_valid(annotation)
and not _is_event_handler_annotation(annotation)[0]
):
msg = (
f"`children` in `{fn.__name__}` must be annotated as "
"`rx.Var[rx.Component]`."
)
raise TypeError(msg)
kind, kind_data = _classify_parameter(annotation, parameter.name, fn.__name__)
spec = _SPECS[kind]
spec.validate(parameter, fn.__name__, for_component)
if kind is MemoParamKind.REST:
rest_count += 1
if rest_count > 1:
msg = f"`@rx.memo` only supports one `rx.RestProp` in `{fn.__name__}`."
raise TypeError(msg)
js_prop_name = format.to_camel_case(parameter.name)
placeholder_name = spec.placeholder_name(
parameter.name, js_prop_name, for_component
)
params.append(
MemoParam(View on GitHub (pinned to 45b8ed5ab7)
Solutions
- Annotate `children` as `rx.Var[rx.Component]`
- Rename the parameter to something like `text` or `content` if it is actually a string value, keeping `children` unclaimed
Example fix
# before
@rx.memo
def card(children: rx.Var[str]) -> rx.Component:
return rx.card(children)
# after
@rx.memo
def card(children: rx.Var[rx.Component]) -> rx.Component:
return rx.card(children) Defensive patterns
Strategy: validation
Validate before calling
import typing, reflex as rx
def check_children_is_component_var(fn) -> None:
ch = typing.get_type_hints(fn).get("children")
if ch is None:
return
if typing.get_origin(ch) is rx.Var and rx.Component in typing.get_args(ch):
return
raise TypeError("children must be annotated rx.Var[rx.Component]") Type guard
import typing, reflex as rx
def is_component_var(ann) -> bool:
return typing.get_origin(ann) is rx.Var and rx.Component in typing.get_args(ann) Prevention
- Reserve `children` for the component slot; name string props `text`/`content`
- Use a shared snippet/typing alias for memo signatures to avoid annotation drift
When it happens
Trigger: Declaring `def my_memo(children: rx.Var[str]) -> rx.Component` or `children: str` — the name matches the reserved slot but the annotation is neither `Var[Component]` nor an EventHandler (which `_validate_event_trigger` rejects separately).
Common situations: Naming a text/content string parameter `children` out of HTML habit; refactoring a component whose content prop was a string; generated code that reuses the name for a different type.
Related errors
- `rx.Var[rx.Component]` parameters in `{fn_name}` must be nam
- `children` in `{fn_name}` cannot be `rx.RestProp`.
- `children` in `{fn_name}` cannot be an `rx.EventHandler`; us
- All parameters of `{fn.__name__}` must be annotated as `rx.V
- Var-returning `@rx.memo` `{func_name}` cannot depend on embe
AI-assisted analysis of reflex-dev/reflex@45b8ed5ab7 (2026-08-28).
Data as JSON: /api/errors/66797c761507a068.
Report an issue: GitHub.