如何修复“带有事件处理程序的静态HTML元素需要角色”? [英] How to fix 'Static HTML elements with event handlers require a role.'?
本文介绍了如何修复“带有事件处理程序的静态HTML元素需要角色”?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的reactjs样式化组件包含以下代码:
My reactjs styledcomponent contains this code:
<a styling="link" onClick={() => this.gotoLink()}>
<SomeComponent />
</a>
这很好,但是随行人员抱怨:
This works fine but the eslint is complaining:
Static HTML elements with event handlers require a role.
如何解决此错误?
推荐答案
您需要在标签中添加角色道具以避免此警告,例如按钮
you need to add a role props in your a tag to avoid this warning, for example a button
<a role = "button" styling="link" onClick={() => this.gotoLink()}>
<SomeComponent />
</a>
我想这是因为锚标记中缺少HREF道具(不确定)
I guess it is because the HREF props is missing in your anchor tag (not sure)
这篇关于如何修复“带有事件处理程序的静态HTML元素需要角色”?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文