{"record":{"id":"8b48b4932d92d1cd","repo":"reflex-dev/reflex","slug":"using-a-componentstate-as-render-fn-inside-rx-f","errorCode":null,"errorMessage":"Using a ComponentState as `render_fn` inside `rx.foreach` is not supported yet.","messagePattern":"Using a ComponentState as `render_fn` inside `rx\\.foreach` is not supported yet\\.","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"packages/reflex-components-core/src/reflex_components_core/core/foreach.py","lineNumber":90,"sourceCode":"            LiteralVar.create(iterable).guess_type()\n            if not isinstance(iterable, Var)\n            else iterable.guess_type()\n        )\n\n        if iterable._var_type == Any:\n            msg = (\n                f\"Could not foreach over var `{iterable!s}` of type Any. \"\n                \"(If you are trying to foreach over a state var, add a type annotation to the var). \"\n                \"See https://reflex.dev/docs/library/dynamic-rendering/foreach/\"\n            )\n            raise ForeachVarError(msg)\n\n        if (\n            hasattr(render_fn, \"__qualname__\")\n            and render_fn.__qualname__ == ComponentState.create.__qualname__\n        ):\n            msg = \"Using a ComponentState as `render_fn` inside `rx.foreach` is not supported yet.\"\n            raise TypeError(msg)\n\n        if isinstance(iterable, ObjectVar):\n            iterable = iterable.entries()\n\n        if isinstance(iterable, StringVar):\n            iterable = iterable.split()\n\n        if not isinstance(iterable, ArrayVar):\n            msg = (\n                f\"Could not foreach over var `{iterable!s}` of type {iterable._var_type}. \"\n                \"See https://reflex.dev/docs/library/dynamic-rendering/foreach/\"\n            )\n            raise ForeachVarError(msg)\n\n        if types.is_optional(iterable._var_type):\n            iterable = cond(iterable, iterable, [])\n\n        component = cls._create(","sourceCodeStart":72,"sourceCodeEnd":108,"githubUrl":"https://github.com/reflex-dev/reflex/blob/45b8ed5ab735f8a56bbb09a42384f030eb0208e7/packages/reflex-components-core/src/reflex_components_core/core/foreach.py#L72-L108","documentation":"Passing a ComponentState's `create` classmethod directly as the render function of `rx.foreach` is not supported: ComponentState creation requires special per-instance setup that the foreach render path cannot perform. It raises TypeError explicitly to fail fast.","triggerScenarios":"`rx.foreach(State.items, ItemComponent.create)` where ItemComponent subclasses rx.ComponentState.","commonSituations":"Trying to render a list of ComponentState-based cards/rows; assuming create behaves like any render callable.","solutions":["Wrap it in a lambda that calls create per item: rx.foreach(State.items, lambda item: ItemComponent.create(item))","Or use a plain function/component instead of ComponentState.create inside foreach","Track the Reflex GitHub issue for native ComponentState support in foreach"],"exampleFix":"# before\nrx.foreach(State.items, ItemCard.create)\n# after\nrx.foreach(State.items, lambda item: ItemCard.create(item))","handlingStrategy":"fallback","validationCode":"rx.foreach(State.items, (lambda it: ItemCard.create(it)) if is_component_state else render_item)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never pass ComponentState.create directly to foreach; wrap in a lambda","Subscribe to Reflex changelog for ComponentState-in-foreach support"],"tags":["reflex","foreach","component-state"],"backgroundTag":"unsupported-api-usage","analyzedSha":"45b8ed5ab735f8a56bbb09a42384f030eb0208e7","analyzedAt":"2026-08-28T19:25:27.644Z","schemaVersion":2},"datasetVersion":"2026-08-28T21:17:43.275Z"}