`Type 'IconType' is not assignable to type 'ReactNode'`
Describe the bug I am using TypeScript for my project. I am trying to create a wrapper for icons from this package.
Expected behavior
I should be able to pass in icons of Type IconType into my Sidebarcon() component for them to be wrapped with <div className="sidebar-icon">.
Screenshots

Desktop (please complete the following information):
- Device: Fedora Linux 36
- Browser Firefox
Hello, fellow react-icons user here.
IconTypes are like react components, not elements. They are meant to be rendered like so: <Icon />.
What I usually do is alias them to a capital-letter name when destructuring (that'd be { icon: Icon }: ... in your example) then you can do <div> <Icon /> </div>
Enjoy!
you are welcome...
I solved the issue by doing something else – making the function accept JSX.Element instead of IconType.
Sorry for not saying anything and silently closing the issue.
I solved the issue by doing something else – making the function accept
JSX.Elementinstead ofIconType.Sorry for not saying anything and silently closing the issue.
How do i do that?
@alikulaOwen instead of the function accepting the icon parameter as IconType, it instead accepts it as a function that returns JSX.Element.
Example:
Instead of
const funcName = ({icon}) => {
return (<div>{icon}</div>)
}
It should be
const funcName = ({Icon}) => {
return (<div> <Icon /> </div>)
}
Hope this helps. :)
Thanks
Hello, fellow react-icons user here.
IconTypes are like react components, not elements. They are meant to be rendered like so:<Icon />.What I usually do is alias them to a capital-letter name when destructuring (that'd be
{ icon: Icon }: ...in your example) then you can do<div> <Icon /> </div>Enjoy!
I like this method, but whenever I pass icon as a prop the following error comes up:
Type 'Element' is not assignable to type 'IconType'. Type 'ReactElement<any, any>' provides no match for the signature '(props: IconBaseProps): Element'.ts(2322)
how could I solve this?
Hello, fellow react-icons user here.
IconTypes are like react components, not elements. They are meant to be rendered like so:<Icon />. What I usually do is alias them to a capital-letter name when destructuring (that'd be{ icon: Icon }: ...in your example) then you can do<div> <Icon /> </div>Enjoy!I like this method, but whenever I pass
iconas a prop the following error comes up:Type 'Element' is not assignable to type 'IconType'. Type 'ReactElement<any, any>' provides no match for the signature '(props: IconBaseProps): Element'.ts(2322)how could I solve this?
never mind guys, I just used the function method:
icon= {() => <ReactIconHere/>}
although I would like to pass just the icon itself