{"record":{"id":"9c004d750ffc914b","repo":"reflex-dev/reflex","slug":"expected-a-component-got-component-called-r-of","errorCode":null,"errorMessage":"Expected a Component, got {component_called!r} of type {type(component_called)}","messagePattern":"Expected a Component, got (.+?) of type (.+?)","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"reflex/compiler/compiler.py","lineNumber":958,"sourceCode":"                \"indices must be integers or slices, not BooleanCastedVar\",\n            )):\n                raise TypeError(\n                    \"Cannot index into a primitive sequence with a Var. Consider calling rx.Var.create() on the sequence.\"\n                ).with_traceback(e.__traceback__) from None\n        if \"CastedVar\" in str(e):\n            raise TypeError(\n                \"Cannot pass a Var to a built-in function. Consider moving the operation to the backend, using existing Var operations, or defining a custom Var operation.\"\n            ).with_traceback(e.__traceback__) from None\n        raise\n    except ReflexError as e:\n        _modify_exception(e)\n        raise\n\n    if (converted := _into_component_once(component_called)) is not None:\n        return converted\n\n    msg = f\"Expected a Component, got {component_called!r} of type {type(component_called)}\"\n    raise TypeError(msg)\n\n\ndef compile_unevaluated_page(\n    route: str,\n    page: UnevaluatedPage,\n    style: ComponentStyle | None = None,\n    theme: Component | None = None,\n) -> Component:\n    \"\"\"Compiles an uncompiled page into a component and adds meta information.\n\n    Args:\n        route: The route of the page.\n        page: The uncompiled page object.\n        style: The style of the page.\n        theme: The theme of the page.\n\n    Returns:\n        The compiled component and whether state should be enabled.","sourceCodeStart":940,"sourceCodeEnd":976,"githubUrl":"https://github.com/reflex-dev/reflex/blob/45b8ed5ab735f8a56bbb09a42384f030eb0208e7/reflex/compiler/compiler.py#L940-L976","documentation":"into_component could not coerce the value returned/used as a component into a Component after trying every conversion path (_into_component_once). It means the render function produced a value Reflex cannot render — typically a non-component object such as a number, dict, or a raw string is handled, but arbitrary objects are not.","triggerScenarios":"A page/render function returns or yields something that is not a Component, str, Var, or convertible value — e.g. returning None implicitly, returning a list mixing in ints, or calling a component function incorrectly (forgetting parentheses so component_called is a function object).","commonSituations":"Forgetting call parentheses (rx.text vs rx.text(...)), early-return None from a conditional render branch, returning raw data structures from a page function, or using a custom object as a child.","solutions":["Ensure the render function returns rx.fragment(...) or a real component in every branch","Check for a missing call: component references passed as children must be invoked","Wrap non-component values: str/int/dict children should be passed inside a component like rx.text(State.value)"],"exampleFix":"# before\ndef index():\n    if not State.ready:\n        return\n    return rx.text(\"hi\")\n# after\ndef index():\n    if not State.ready:\n        return rx.fragment()\n    return rx.text(\"hi\")","handlingStrategy":"validation","validationCode":"root = index()\nassert root is None or isinstance(root, (rx.Component, str)), f\"bad page root: {root!r}\"","typeGuard":"def is_renderable(v) -> bool:\n    return v is None or isinstance(v, (rx.Component, str, rx.Var))","tryCatchPattern":null,"preventionTips":["Always return a Component from every branch of render functions","Lint for bare component references (missing parentheses) passed as children","Add a smoke test that calls each page function and checks its return type"],"tags":["reflex","component","render","typeerror"],"backgroundTag":"invalid-component-child","analyzedSha":"45b8ed5ab735f8a56bbb09a42384f030eb0208e7","analyzedAt":"2026-08-28T19:25:27.644Z","schemaVersion":2},"datasetVersion":"2026-08-28T21:17:43.275Z"}