6

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>
  );
};
3
  • 1
    Have a look at: developer.mozilla.org/en-US/docs/Web/API/HTMLAnchorElement
    – user0101
    Commented May 27, 2020 at 9:05
  • 1
    I'm afraid it's not clear what you're asking here. Maybe you could get a colleague to help you write the question? But regarding "I could not see an 'HTMLAElement' structure": The type of an a element is HTMLAnchorElement. You can find those types in this list in the HTML5 specification. Commented May 27, 2020 at 9:05
  • Thank you 🙏 🙏 🙏 . I did not know that the element 'a' corresponds to 'anchor'. my shame 🤦🏻
    – yunusunver
    Commented May 27, 2020 at 9:10

1 Answer 1

10

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.