{"record":{"id":"f6e000bc50c56aa4","repo":"reflex-dev/reflex","slug":"f-icon-name-must-be-a-string-got-tag-var-var-ty","errorCode":null,"errorMessage":"f\"Icon name must be a string, got {tag_var._var_type}\"","messagePattern":"f\"Icon name must be a string, got (.+?)\"","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"packages/reflex-components-lucide/src/reflex_components_lucide/icon.py","lineNumber":75,"sourceCode":"            else:\n                msg = f\"Passing multiple children to Icon component is not allowed: remove positional arguments {children[1:]} to fix\"\n                raise AttributeError(msg)\n        if \"tag\" not in props:\n            msg = \"Missing 'tag' keyword-argument for Icon\"\n            raise AttributeError(msg)\n\n        tag_var: Var | LiteralVar = Var.create(props.pop(\"tag\"))\n        if isinstance(tag_var, LiteralVar):\n            if isinstance(tag_var, LiteralStringVar):\n                tag = format.to_snake_case(tag_var._var_value.lower())\n            else:\n                msg = f\"Icon name must be a string, got {type(tag_var)}\"\n                raise TypeError(msg)\n        elif isinstance(tag_var, Var):\n            tag_stringified = tag_var.guess_type()\n            if not isinstance(tag_stringified, StringVar):\n                msg = f\"Icon name must be a string, got {tag_var._var_type}\"\n                raise TypeError(msg)\n            return DynamicIcon.create(name=tag_stringified.replace(\"_\", \"-\"), **props)\n\n        if tag not in LUCIDE_ICON_LIST:\n            icons_sorted = sorted(\n                LUCIDE_ICON_LIST,\n                key=lambda s, tag=tag: format.length_of_largest_common_substring(\n                    tag, s\n                ),\n                reverse=True,\n            )\n            logger.warning(\n                f\"Invalid icon tag: {tag}. Please use one of the following: {', '.join(icons_sorted[0:10])}, ...\"\n                \"\\nSee full list at https://reflex.dev/docs/library/data-display/icon/#icons-list. Using 'circle_help' icon instead.\"\n            )\n            tag = \"circle_help\"\n\n        props[\"tag\"] = LUCIDE_ICON_MAPPING_OVERRIDE.get(tag, format.to_title_case(tag))\n        props[\"alias\"] = f\"Lucide{props['tag']}\"","sourceCodeStart":57,"sourceCodeEnd":93,"githubUrl":"https://github.com/reflex-dev/reflex/blob/45b8ed5ab735f8a56bbb09a42384f030eb0208e7/packages/reflex-components-lucide/src/reflex_components_lucide/icon.py#L57-L93","documentation":"When `tag` is a runtime Var (not a literal), Reflex guesses its type to decide whether a DynamicIcon can be rendered. If the Var's inferred type is not a string (int, bool, list, etc.), TypeError is raised because the client cannot look up an icon by a non-string name.","triggerScenarios":"rx.icon(tag=State.count) with count: int, or a Var whose _var_type is not str (e.g. an object or number field).","commonSituations":"Storing icon selection as an index/enum int in state instead of the icon name string.","solutions":["Type the state field as str: icon_name: str = 'home', then rx.icon(tag=State.icon_name)","Convert ints to names server-side (in an event handler) before assigning to the icon state field"],"exampleFix":"# before\nclass S(rx.State):\n    icon: int = 0\nrx.icon(tag=S.icon)\n# after\nclass S(rx.State):\n    icon: str = 'home'\nrx.icon(tag=S.icon)","handlingStrategy":"type-guard","validationCode":"# ensure the state field is str-typed\nclass State(rx.State):\n    icon_name: str = 'home'","typeGuard":"def icon_var_is_str(var) -> bool:\n    return var._var_type is str or issubclass(var._var_type, str)","tryCatchPattern":null,"preventionTips":["Store icon names as str in state, never indices/enums","Annotate state fields used in components"],"tags":["reflex","lucide","icon","var-type","type-error"],"backgroundTag":"component-prop-validation","analyzedSha":"45b8ed5ab735f8a56bbb09a42384f030eb0208e7","analyzedAt":"2026-08-28T19:25:27.644Z","schemaVersion":2},"datasetVersion":"2026-08-28T21:17:43.275Z"}