consider the code below:
interface ILink {
clicked: (event: React.MouseEvent<HTMLDivElement, MouseEvent>) => void;
Icon: OverridableComponent<SvgIconTypeMap<{}, 'svg'>>;
children: string;
className: string;
color: string;
}
const Link: React.FC<ILink> = ({
Icon,
children,
color,
clicked,
className
}) => {
const colorClass: React.CSSProperties = { color };
return (
<div onClick={clicked} className={className}>
<Icon style={colorClass} />
<p style={colorClass}>{children}</p>
</div>
);
};
const Navbar: React.FC<INavbar> = ({ setPage }) => {
const [isActive, setIsActive] = useState<string>('home');
const handleClick = (menuItem: string) => {
setPage(menuItem);
setIsActive(menuItem);
};
return (
<nav className='sidebarOptions'>
<section>
<Link
className='sidebarLink logo'
Icon={GamesIcon}
color={isActive === 'home' ? 'white' : 'grey'}
clicked={() => handleClick('home')}>
Better Games
</Link>
// ... more code
</section>
</nav>
);
};
my problem is with 'clicked' type on ILink interface, especifically.
the principle of typescript is to define a type to a thing (a property in my case) that i am going to use, but if i try to specify the property 'clicked' as it is: () => (menuItem: string) => void, it throws a compile time error, but if specify 'clicked' as the description of onClick it works.
please, I need explanations regarding that or if you have links from articles, courses or whatever I can find to learn better about that, please, insert in.
regards.