{"record":{"id":"9bde956d5f823ad8","repo":"reflex-dev/reflex","slug":"var-returning-rx-memo-func-name-cannot-depe","errorCode":null,"errorMessage":"Var-returning `@rx.memo` `{func_name}` cannot depend on hooks. Use a component-returning `@rx.memo` instead.","messagePattern":"Var-returning `@rx\\.memo` `(.+?)` cannot depend on hooks\\. Use a component-returning `@rx\\.memo` instead\\.","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"packages/reflex-base/src/reflex_base/components/memo.py","lineNumber":808,"sourceCode":"    \"\"\"Validate that a var-returning memo can compile safely.\n\n    Args:\n        return_expr: The return expression.\n        func_name: The function name for error messages.\n\n    Raises:\n        TypeError: If the return expression depends on unsupported features.\n    \"\"\"\n    var_data = VarData.merge(return_expr._get_all_var_data())\n    if var_data is None:\n        return\n\n    if var_data.hooks:\n        msg = (\n            f\"Var-returning `@rx.memo` `{func_name}` cannot depend on hooks. \"\n            \"Use a component-returning `@rx.memo` instead.\"\n        )\n        raise TypeError(msg)\n\n    if var_data.components:\n        msg = (\n            f\"Var-returning `@rx.memo` `{func_name}` cannot depend on embedded \"\n            \"components, custom code, or dynamic imports. Use a component-returning \"\n            \"`@rx.memo` instead.\"\n        )\n        raise TypeError(msg)\n\n    bundled_libraries = RegistrationContext.ensure_context().bundled_libraries\n    for lib in dict(var_data.imports):\n        if not lib:\n            continue\n        if lib.startswith((\".\", \"/\", \"$/\", \"http\")):\n            continue\n        if format.format_library_name(lib) in bundled_libraries:\n            continue\n        msg = (","sourceCodeStart":790,"sourceCodeEnd":826,"githubUrl":"https://github.com/reflex-dev/reflex/blob/45b8ed5ab735f8a56bbb09a42384f030eb0208e7/packages/reflex-base/src/reflex_base/components/memo.py#L790-L826","documentation":"ComponentState classes are marked as mixins; Reflex instantiates them only through ComponentState.create(...), which wires them into the app's state tree. Directly constructing the underlying State (e.g. `MyComponentState()`) raises ReflexRuntimeError.","triggerScenarios":"Calling `ComponentStateSubclass(...)` directly — including via `get_state` misuse on the mixin, pickling/reconstructing it standalone, or instantiating it in tests.","commonSituations":"Treating a ComponentState like a normal State in unit tests; passing the class where Reflex expects an instance created by `create()`.","solutions":["Use `inst = MyComponentState.create()` once, then access state via `MyComponentState.State`","In tests, instantiate via create() or test through the parent app state tree","Never directly construct ComponentState subclasses"],"exampleFix":"// before\nstate = CounterState()\n// after\nCounterState.create()\nstate = CounterState.State","handlingStrategy":"validation","validationCode":"assert not getattr(MyComponentState, \"_mixin\", False) or using_create, \"call ComponentState.create() instead\"","typeGuard":null,"tryCatchPattern":"try:\n    st = MyComponentState()\nexcept ReflexRuntimeError:\n    MyComponentState.create()\n    st = MyComponentState.State","preventionTips":["Always obtain ComponentState instances via create()","Access state through the .State attribute in tests"],"tags":["reflex","component-state","instantiation","api-misuse"],"backgroundTag":"invalid-direct-instantiation","analyzedSha":"45b8ed5ab735f8a56bbb09a42384f030eb0208e7","analyzedAt":"2026-08-28T19:25:27.644Z","schemaVersion":2},"datasetVersion":"2026-08-28T21:17:43.275Z"}