Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Extending HTML anchor elements in React and TypeScript

I am using typescript in a React project and I want to add tag's props. I can access the properties of the link element but not the properties a element. I am getting an error when the properties of the link tag use an a tag.

Is there an 'HTMLAElement' structure for an element a in React?

const MyComponent: FunctionComponent<React.LinkHTMLAttributes<HTMLLinkElement>> = (
  props: React.LinkHTMLAttributes<HTMLLinkElement>,
) => {
  return (
      <a {...props} className="mycomponent">  // When I use it with the <link> it doesn't give an error but I need <a>.
          MyComponent
      </a>
  );
};
like image 689
yunusunver Avatar asked Jun 09 '26 07:06

yunusunver


1 Answers

My problem is solved. Errors disappeared when I used 'HTMLAnchorElement'. I did not know that the element 'a' corresponds to 'anchor'.

like image 118
yunusunver Avatar answered Jun 10 '26 22:06

yunusunver



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!