I'm creating a reusable 'button' and I want to add a href to take it to another page when clicked.
ERROR:
The type '{ children: ReactNode; href: string; onMouseOver: (event: any) => void; onMouseOut: (event: any) => void; style: CSSProperties; }' cannot be assigned to type 'DetailedHTMLProps<ButtonHTMLAttributes, HTMLButtonElement>'.
Property 'href' does not exist on type 'DetailedHTMLProps<ButtonHTMLAttributes, HTMLButtonElement>'. Did you mean 'ref'?
O codigo:
import React from 'react';
type ButtonProps = {
style: React.CSSProperties;
children: React.ReactNode;
href: string;
};
function MouseOver(event: any) {
event.target.style.opacity = '90%'
}
function MouseOut(event: any) {
event.target.style.opacity = ''
}
function Button({ style, children, href }: ButtonProps) {
return (
<button
href={href}
onMouseOver={MouseOver}
onMouseOut={MouseOut}
style={style}
>
{children}
</button>
)
}
export default Button;
I've already tried using this possibility:
import Link from 'next/link'
function Button({ style, children, href }: ButtonProps) {
return (
<Link href={href}>
<button
onMouseOver={MouseOver}
onMouseOut={MouseOut}
style={style}
>
{children}
</button>
</Link>
)
}
This way it works, but the code requires that all buttons I'm reusing must put a href and I just want only 1 button to have the href that will take me to a page of registration.