I create a dynamic button (Comp) in React TypeScript. "Comp" can be a button, anchor, or Link (React Router). I got a problem with the type having no properties in common with the type 'IntrinsicAttributes'
.
type ButtonProps = {
href?: string;
to?: string;
children: ReactNode;
};
function Button(props: ButtonProps) {
const { href, to, children } = props;
let Comp = 'button';
if (href) Comp = 'a';
if (to) Comp = 'Link';
const compProps = {
href,
to,
};
return <Comp {...compProps}>{children}</Comp>;
}
Here is the problem:
Type '{ children: ReactNode; href: string | undefined; to: string | undefined; }' has no properties in common with type 'IntrinsicAttributes'.ts(2559).
I researched some pics in StackOverflow but it's not my case.