aykutkardas / react-icomoon

It makes it very simple to use SVG icons in your React and React-Native projects.
https://svgps.app
MIT License
216 stars 22 forks source link

Export IconProps interface #30

Closed hristo-enev closed 2 years ago

hristo-enev commented 2 years ago

Typescript will complain if I want to introduce a default icon size, for example, because I can't point to the correct IconProps.

export const Icon: typeof IconComponent = ({ size, ...rest }: IconProps) => (
  <IcoMoon iconSet={IconSet} size={size || 14} {...rest} />
);

or

export const Icon: typeof IconComponent = (props: IconProps) => <IcoMoon iconSet={IconSet} {...props} size={props.size || 14} />;
vercel[bot] commented 2 years ago

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/aykutkardas/react-icomoon/E3sYY3Fqcstm7PvGXgCCUGd1TuF2
✅ Preview: https://react-icomoon-git-fork-hristo-enev-patch-1-aykutkardas.vercel.app

aykutkardas commented 2 years ago

IconComponent should contain props as well. Did you have a problem while using it?

hristo-enev commented 2 years ago

IconComponent should contain props as well. Did you have a problem while using it?

Yes, as I said Typescript will complain about the above examples I have provided. Also another use case would be to add new props to my Icon component. Then I would need to define an interface that extends IconProps, but I cannot import IconProps. Basically what I'm trying to say is - exporting just IconComponent and relying that everyone would create an Icon component that is a typeof IconComponent is limiting. Sometimes you might want to create a bit different component that have different props for example but still relies on IconProps main props.

aykutkardas commented 2 years ago

You are right, I agree with you. Thanks for your contribution. 🎉