reflex-dev/reflex · error · AttributeError

f"Icon name must be a string, got {children[0]._var_type if

Error message

f"Icon name must be a string, got {children[0]._var_type if isinstance(children[0], Var) else children[0]}"

What it means

rx.icon() (lucide) accepts a single icon name as its only child/positional argument, and that name must resolve to a string Var. If the value's inferred type is not a string (e.g. an int, bool, or object Var), Reflex raises AttributeError at component creation time because it cannot map the value to a lucide icon tag.

Source

Thrown at packages/reflex-components-lucide/src/reflex_components_lucide/icon.py:55

        Run some additional checks on Icon component.

        Args:
            *children: The positional arguments
            **props: The keyword arguments

        Returns:
            The created component.

        Raises:
            AttributeError: The errors tied to bad usage of the Icon component.
            TypeError: If the icon name is not a string.
        """
        if children:
            if len(children) == 1:
                child = Var.create(children[0]).guess_type()
                if not isinstance(child, StringVar):
                    msg = f"Icon name must be a string, got {children[0]._var_type if isinstance(children[0], Var) else children[0]}"
                    raise AttributeError(msg)
                props["tag"] = children[0]
            else:
                msg = f"Passing multiple children to Icon component is not allowed: remove positional arguments {children[1:]} to fix"
                raise AttributeError(msg)
        if "tag" not in props:
            msg = "Missing 'tag' keyword-argument for Icon"
            raise AttributeError(msg)

        tag_var: Var | LiteralVar = Var.create(props.pop("tag"))
        if isinstance(tag_var, LiteralVar):
            if isinstance(tag_var, LiteralStringVar):
                tag = format.to_snake_case(tag_var._var_value.lower())
            else:
                msg = f"Icon name must be a string, got {type(tag_var)}"
                raise TypeError(msg)
        elif isinstance(tag_var, Var):
            tag_stringified = tag_var.guess_type()
            if not isinstance(tag_stringified, StringVar):

View on GitHub (pinned to 45b8ed5ab7)

Solutions

  1. Pass a string icon name: rx.icon('home')
  2. If using state, ensure the Var is typed str: rx.icon(State.icon_name) where icon_name: str
  3. For non-string data, convert before passing: rx.icon(str(State.value)) won't help for Vars — store the name as a str state field instead

Example fix

# before
rx.icon(123)
# after
rx.icon('home')
Defensive patterns

Strategy: type-guard

Validate before calling

name = 'home'
assert isinstance(name, str), 'icon name must be a str'

Type guard

def is_icon_name(v) -> bool:
    from reflex.vars import Var
    return isinstance(v, str) or (isinstance(v, Var) and v._var_type is str)

Prevention

When it happens

Trigger: rx.icon(123), rx.icon(State.count) where count is an int, or passing a component/object as the icon name.

Common situations: Passing a state variable holding an icon index or an enum/int instead of the icon name string; passing rx.text('home') as a child.

Related errors


AI-assisted analysis of reflex-dev/reflex@45b8ed5ab7 (2026-08-28). Data as JSON: /api/errors/a84271d51c6262b0. Report an issue: GitHub.