Skip to content

slots not working with prop as a component pattern #657

@samiresua

Description

@samiresua

I know slots are not officially released, but thought i would share this finding incase you were not already aware. Are there plans to support this pattern?

The below works as expected:

type ButtonProps = {
  icon: ReactElement<IconProps>;
};

export const ButtonWithIconElement = ({
  icon,
}: ButtonProps) => {
  return (
    <button>
      {icon}
    </button>
  );
};

However, the when using the below pattern slots throw an error

type ButtonProps = {
  Icon: ComponentType<IconProps>;
};

export const ButtonWithIconComponent = ({
  Icon,
}: ButtonProps) => {
  return (
    <button>
      // our Icon is a component
      // its name starts with a capital letter to signal that
      // so we can just render it here as any other component
      <Icon />
    </button>
  );
};

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions