reflex-dev/reflex · error · TypeError
`children` in `{fn_name}` cannot be an `rx.EventHandler`; us
Error message
`children` in `{fn_name}` cannot be an `rx.EventHandler`; use `rx.Var[rx.Component]`. What it means
In a component-returning `@rx.memo`, the reserved `children` slot was annotated as `rx.EventHandler`. The children slot must be `rx.Var[rx.Component]` because it receives rendered child elements, not an event callback. Reflex raises this TypeError at decoration time during event-trigger validation.
Source
Thrown at packages/reflex-base/src/reflex_base/components/memo.py:961
msg = f"`children` in `{fn_name}` cannot be `rx.RestProp`."
raise TypeError(msg)
def _validate_event_trigger(
parameter: inspect.Parameter, fn_name: str, for_component: bool
) -> None:
if not for_component:
msg = (
f"`rx.EventHandler` parameters are only supported on component-"
f"returning memos. Got `{parameter.name}` in `{fn_name}`."
)
raise TypeError(msg)
if parameter.name == "children":
msg = (
f"`children` in `{fn_name}` cannot be an `rx.EventHandler`; "
"use `rx.Var[rx.Component]`."
)
raise TypeError(msg)
if parameter.default is not inspect.Parameter.empty:
msg = (
f"`rx.EventHandler` parameter `{parameter.name}` in `{fn_name}` "
"must not have a default value."
)
raise TypeError(msg)
def _placeholder_name_value(name: str, js_prop_name: str, for_component: bool) -> str:
return js_prop_name + CAMEL_CASE_MEMO_MARKER if for_component else name
def _placeholder_name_passthrough(
name: str, js_prop_name: str, for_component: bool
) -> str:
return name
View on GitHub (pinned to 45b8ed5ab7)
Solutions
- Annotate `children` as `rx.Var[rx.Component]`
- If a callback is needed, add a separately named `rx.EventHandler` parameter (e.g. `on_click: rx.EventHandler`)
Example fix
// before
@rx.memo
def dialog(children: rx.EventHandler) -> rx.Component:
...
// after
@rx.memo
def dialog(children: rx.Var[rx.Component], on_close: rx.EventHandler) -> rx.Component:
... Defensive patterns
Strategy: validation
Validate before calling
import inspect, typing, reflex as rx
def check_children_annotation(fn) -> None:
hints = typing.get_type_hints(fn)
if hints.get("children") is rx.EventHandler:
raise TypeError("children must be rx.Var[rx.Component], not rx.EventHandler") Type guard
import typing, reflex as rx
def children_slot_ok(fn) -> bool:
hints = typing.get_type_hints(fn)
ch = hints.get("children")
return ch is None or (typing.get_origin(ch) is rx.Var and rx.Component in typing.get_args(ch)) Prevention
- Treat `children` as a component slot, never a callback
- Name event triggers with on_* prefixes (on_click, on_close)
When it happens
Trigger: Declaring `def my_memo(children: rx.EventHandler) -> rx.Component` — the parameter is named `children` but annotated `rx.EventHandler` instead of `rx.Var[rx.Component]`.
Common situations: Confusing the children slot with an event trigger; wanting a callback when children render and reaching for the wrong annotation; auto-generated signatures that annotate every callable prop as EventHandler.
Related errors
- `rx.Var[rx.Component]` parameters in `{fn_name}` must be nam
- `children` in `{fn_name}` cannot be `rx.RestProp`.
- `rx.EventHandler` parameters are only supported on component
- `rx.EventHandler` parameter `{parameter.name}` in `{fn_name}
- `children` in `{fn.__name__}` must be annotated as `rx.Var[r
AI-assisted analysis of reflex-dev/reflex@45b8ed5ab7 (2026-08-28).
Data as JSON: /api/errors/51df1534235a7bcb.
Report an issue: GitHub.