{"record":{"id":"5553bdb7603eeffc","repo":"reflex-dev/reflex","slug":"component-returning-rx-memo-fn-name-mus","errorCode":null,"errorMessage":"Component-returning `@rx.memo` `{fn.__name__}` must return an `rx.Component` or `rx.Var[rx.Component]`.","messagePattern":"Component-returning `@rx\\.memo` `(.+?)` must return an `rx\\.Component` or `rx\\.Var\\[rx\\.Component\\]`\\.","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"packages/reflex-base/src/reflex_base/components/memo.py","lineNumber":1457,"sourceCode":"        rest_target_fields: Accumulator populated with the field names of the\n            component(s) the body spreads an ``rx.RestProp`` onto.\n        runtime_values: Optional runtime values keyed by parameter name.\n\n    Returns:\n        The wrapped component the body returned.\n\n    Raises:\n        TypeError: If the body does not return a component.\n    \"\"\"\n    body = _normalize_component_return(\n        _evaluate_memo_function(fn, params, runtime_values)\n    )\n    if body is None:\n        msg = (\n            f\"Component-returning `@rx.memo` `{fn.__name__}` must return an \"\n            \"`rx.Component` or `rx.Var[rx.Component]`.\"\n        )\n        raise TypeError(msg)\n    return _lift_rest_props(body, rest_target_fields)\n\n\ndef _evaluate_function_body(\n    fn: Callable[..., Any], params: tuple[MemoParam, ...]\n) -> ArgsFunctionOperation:\n    \"\"\"Run a var memo's body and build its compiled function.\n\n    Args:\n        fn: The decorated function.\n        params: The analyzed memo parameters.\n\n    Returns:\n        The compiled ``ArgsFunctionOperation`` for the memo body.\n    \"\"\"\n    return_expr = Var.create(_evaluate_memo_function(fn, params))\n    _validate_var_return_expr(return_expr, fn.__name__)\n    return _build_args_function(params, return_expr)","sourceCodeStart":1439,"sourceCodeEnd":1475,"githubUrl":"https://github.com/reflex-dev/reflex/blob/45b8ed5ab735f8a56bbb09a42384f030eb0208e7/packages/reflex-base/src/reflex_base/components/memo.py#L1439-L1475","documentation":"A component-returning `@rx.memo` function must actually return an `rx.Component` or an `rx.Var[rx.Component]`. When Reflex evaluates the memo body and gets `None` (e.g. the function falls through without a return, or returns None conditionally), it raises this TypeError.","triggerScenarios":"Decorating a function with `@rx.memo` whose body has no `return`, returns `None` on some path, or returns a non-component value. Raised when the memo is evaluated (`_memo_impl` / `_create_component_definition` -> `_evaluate_component_body`).","commonSituations":"Skeleton/stub functions decorated with `@rx.memo` before the body is written; early `return` statements (including implicit None) in branching render logic; returning a `list` or `str` instead of a single component; typos where the return statement was deleted during refactor.","solutions":["Ensure every code path returns an `rx.Component` (e.g. `rx.fragment(...)`, `rx.box(...)`) or `rx.Var[rx.Component]`.","Wrap multi-element returns in `rx.fragment` or use `rx.cond` for conditional rendering instead of returning None.","If the memo is meant to compute a value, not a component, use a different mechanism (e.g. computed `rx.Var` in state) rather than a component memo."],"exampleFix":"# before\n@rx.memo\ndef item(label: rx.Var[str]):\n    if label:\n        return rx.text(label)\n\n# after\n@rx.memo\ndef item(label: rx.Var[str]):\n    return rx.cond(label, rx.text(label), rx.text(\"empty\"))","handlingStrategy":"validation","validationCode":"import reflex as rx\n\ndef returns_component(fn, *args):\n    result = fn(*args)\n    return isinstance(result, rx.Component) or isinstance(result, rx.Var)","typeGuard":"import reflex as rx\n\ndef is_component_or_var(value) -> bool:\n    return isinstance(value, (rx.Component, rx.Var))","tryCatchPattern":"try:\n    node = memo_fn(props)\nexcept TypeError as e:\n    if \"must return an\" in str(e):\n        return rx.fragment()  # safe placeholder while the memo body is fixed\n    raise","preventionTips":["Every branch of a component memo must return an rx.Component; use rx.cond for conditional rendering instead of returning None.","Unit-test memo functions by calling them with representative props and asserting the result is a Component.","Avoid decorating stub functions with @rx.memo until they return something."],"tags":["reflex","memo","return-value","component","typeerror"],"backgroundTag":"missing-return-value","analyzedSha":"45b8ed5ab735f8a56bbb09a42384f030eb0208e7","analyzedAt":"2026-08-28T19:25:27.644Z","schemaVersion":2},"datasetVersion":"2026-08-28T21:17:43.275Z"}