tabler-icons: 3.0 breaking changes?

I was using TablerIconProps in 2.x in the following way:

const lookup = Record<string, (props: TablerIconProps) => JSX.Element) = {
   key: IconFoo,
   key2: IconBar, ...

In 3.0 TablerIconProps is has been renamed IconProps, but also because the icons are now a ForwardRefExoticComponent, they no longer match (props: IconProps) => JSX.Element…

Type 'ForwardRefExoticComponent<Omit<IconProps, "ref"> & RefAttributes<SVGSVGElement>>' is not assignable to type '(props: IconProps) => Element'.
 Type 'ReactNode' is not assignable to type 'Element'.
   Type 'undefined' is not assignable to type 'ReactElement<any, any>'

changing the type to (props: IconProps) => ReactNode solves the problem…

Should this have been documented in the release notes for 3.0?

Also, I think changing the name from TablerIconsProps to IconProps was a poor choice, since every other IconXXX export is an actual Icon… what if someone wanted to make an icon for properties and wanted to call it IconProps?

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 9
  • Comments: 17 (12 by maintainers)

Most upvoted comments

I’ve upgraded from version 2.47.0 to 3.2.0 and created this custom type to address backward compatibility issues.

import { IconProps } from '@tabler/icons-react';

export type TablerIconsProps = Partial<
  ForwardRefExoticComponent<Omit<IconProps, 'ref'> & RefAttributes<FunctionComponent<IconProps>>>
> & {
  className?: string;
  size?: string | number;
  stroke?: string | number;
  strokeWidth?: string | number;
  style?: CSSProperties;
};

I hope it’s useful.

I believe they merged my PR on April 30…

https://github.com/tabler/tabler-icons/pull/1058

@naughton @CHE1RON is this issue fixed in the newest versions of @tabler/icons-react?

I was using Tabler Icon this way in 2.4.7…

--- Usage
<PageIconHome size={iconSize} strokeWidth={IconStrokeWidth} />


-- Common
import {
TablerIconsProps
} from "@tabler/icons-react";

export const PageIconHome = (props: TablerIconsProps) => (
  <IconHome2 {...defaultIconProps} {...props} />
);

Now i’m using it this way in 3.1.0…

--- Usage
<PageIconHome size={iconSize} strokeWidth={IconStrokeWidth} />


-- Common
import {
  Icon,
  IconProps
} from "@tabler/icons-react";

interface TablerIconProps
  extends Partial<
    ForwardRefExoticComponent<
      Omit<IconProps, "ref"> & RefAttributes<Icon>
    >
  > {
  size?: string | number;
  stroke?: string | number;
  strokeWidth?: string | number;
  className?: string;
}

export const PageIconHome = (props: TablerIconProps) => (
  <IconHome2 {...defaultIconProps} {...props} />
  );

This is allowing us to create icon components and use them in multiple areas while only have a single Icon declared. We can also override the icon props as required for specific use cases.

From version 3, the implementation outside of the library is a lot more complex and seems unnecessary. I do agree with the comments in this thread. However, I don’t think the type suggested quite fits our use case.

maybe you could export a type like this for a better “dx”?

import { ForwardRefExoticComponent, RefAttributes, FunctionComponent } from "react";

export type TablerIcon = ForwardRefExoticComponent<
  Omit<IconProps, "ref"> & RefAttributes<FunctionComponent<IconProps>>
>;

@naughton @dandudzi those changes are non intentional, I’m working on w 3.0.1 with fixes