Categories
React Answers

How to fix ‘Static HTML elements with event handlers require a role.’ warning in React?

Spread the love

Sometimes, we want to fix ‘Static HTML elements with event handlers require a role.’ warning in React.

In this article, we’ll look at how to fix ‘Static HTML elements with event handlers require a role.’ warning in React.

How to fix ‘Static HTML elements with event handlers require a role.’ warning in React?

To fix ‘Static HTML elements with event handlers require a role.’ warning in React, we should set the role attribute of the a element.

For instance, we write:

import React from "react";

export default function App() {
  return (
    <div>
      <a role="button" onClick={() => alert("hello")}>
        hello
      </a>
    </div>
  );
}

to set the role attribute of the a element to button.

Conclusion

To fix ‘Static HTML elements with event handlers require a role.’ warning in React, we should set the role attribute of the a element.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *