How to fix 'Static HTML elements with event handlers require a role.'?

bier hier picture bier hier · Jan 20, 2019 · Viewed 29.3k times · Source

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.

How can I fix this error?

Answer

Jerome  picture Jerome · Jan 20, 2019

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>

I guess it is because the HREF props is missing in your anchor tag (not sure)