在 React 和 TypeScript 中扩展 HTML <a> 标签元素
Extending HTML <a> tag elements in React and TypeScript
我在 React 项目中使用 typescript,我想添加标签的属性。我可以访问 link
元素的属性,但不能访问 a
元素的属性。 link
标签的属性使用 a
标签时出现错误。
React 中的元素 a
是否有 'HTMLAElement' 结构?
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>
);
};
我的问题解决了。当我使用 'HTMLAnchorElement' 时错误消失了。我不知道元素 'a' 对应于 'anchor'.
我在 React 项目中使用 typescript,我想添加标签的属性。我可以访问 link
元素的属性,但不能访问 a
元素的属性。 link
标签的属性使用 a
标签时出现错误。
React 中的元素 a
是否有 'HTMLAElement' 结构?
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>
);
};
我的问题解决了。当我使用 'HTMLAnchorElement' 时错误消失了。我不知道元素 'a' 对应于 'anchor'.