Search code examples
javascriptreactjstypescripthtmlelements

Extending HTML <a> tag 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>
  );
};

Solution

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