{"record":{"id":"5e92d160b4f96b09","repo":"reflex-dev/reflex","slug":"cls-name-must-implement-get-component-to-ret","errorCode":null,"errorMessage":"{cls.__name__} must implement get_component to return the component instance.","messagePattern":"(.+?) must implement get_component to return the component instance\\.","errorType":"exception","errorClass":"NotImplementedError","httpStatus":null,"severity":"error","filePath":"reflex/state.py","lineNumber":2565,"sourceCode":"        Args:\n            mixin: Whether the subclass is a mixin and should not be initialized.\n            **kwargs: The kwargs to pass to the init_subclass method.\n        \"\"\"\n        super().__init_subclass__(mixin=mixin, **kwargs)\n\n    @classmethod\n    def get_component(cls, *children, **props) -> Component:\n        \"\"\"Get the component instance.\n\n        Args:\n            children: The children of the component.\n            props: The props of the component.\n\n        Raises:\n            NotImplementedError: if the subclass does not override this method.\n        \"\"\"\n        msg = f\"{cls.__name__} must implement get_component to return the component instance.\"\n        raise NotImplementedError(msg)\n\n    @classmethod\n    def create(cls, *children, **props) -> Component:\n        \"\"\"Create a new instance of the Component.\n\n        Args:\n            children: The children of the component.\n            props: The props of the component.\n\n        Returns:\n            A new instance of the Component with an independent copy of the State.\n        \"\"\"\n        from reflex.compiler.compiler import into_component\n\n        cls._per_component_state_instance_count += 1\n        state_cls_name = f\"{cls.__name__}_n{cls._per_component_state_instance_count}\"\n        component_state = type(\n            state_cls_name,","sourceCodeStart":2547,"sourceCodeEnd":2583,"githubUrl":"https://github.com/reflex-dev/reflex/blob/45b8ed5ab735f8a56bbb09a42384f030eb0208e7/reflex/state.py#L2547-L2583","documentation":"Raised by ComponentState.get_component (via State subclass mixin) when a component-state class does not override the get_component classmethod. Reflex's ComponentState pattern requires each subclass to return the component instance it manages; the base implementation deliberately raises NotImplementedError to enforce the contract.","triggerScenarios":"Creating a class that inherits rx.ComponentState (or ComponentStateMixin) without defining a `get_component` classmethod, then accessing/instantiating it so the base get_component is called (typically during App.add_page or rendering of the state's component).","commonSituations":"Copying a rx.ComponentState example but renaming/deleting the get_component method; refactoring a component out and forgetting to keep get_component; inheriting from the mixin for utilities without intending to render a component.","solutions":["Add a `@classmethod def get_component(cls, *children, **props)` to the subclass that returns the component instance, e.g. `return rx.text(cls.value)`","If you don't need per-component state, inherit from rx.State instead of rx.ComponentState","If the class is abstract intermediate, mark it abstract and only instantiate concrete leaf classes that implement get_component"],"exampleFix":"// before\nclass MyState(rx.ComponentState):\n    value: str = \"hi\"\n\n// after\nclass MyState(rx.ComponentState):\n    value: str = \"hi\"\n\n    @classmethod\n    def get_component(cls, *children, **props):\n        return rx.text(cls.value, **props)","handlingStrategy":"type-guard","validationCode":"def has_get_component(cls) -> bool:\n    return callable(getattr(cls, \"get_component\", None)) and \"get_component\" not in rx.ComponentState.__dict__ or cls.get_component is not rx.ComponentState.get_component","typeGuard":"from reflex import rx\n\ndef implements_get_component(cls: type) -> bool:\n    return cls.get_component is not rx.ComponentState.get_component","tryCatchPattern":"try:\n    comp = MyComponentState.get_component()\nexcept NotImplementedError:\n    # subclass missing get_component; handle or skip rendering\n    comp = rx.fragment()","preventionTips":["Treat rx.ComponentState subclasses as abstract until get_component is defined","Add a unit test asserting each ComponentState subclass overrides get_component"],"tags":["reflex","component-state","not-implemented","subclass-contract"],"backgroundTag":"abstract-method-not-implemented","analyzedSha":"45b8ed5ab735f8a56bbb09a42384f030eb0208e7","analyzedAt":"2026-08-28T19:25:27.644Z","schemaVersion":2},"datasetVersion":"2026-08-28T21:17:43.275Z"}