Languages

React - the href attribute requires a valid value to be accessible warning

1 points
Asked by:
Lily
548

How can I fix the following warning in React?

Warning:

The href attribute requires a valid value to be accessible.
Provide a valid, navigable address as the href value.
If you cannange it with appropriate styles.
Learn more: https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/blob/HEAD/docs/rules/anchor-is-valid.md

My code:

import React from 'react';
import './MyComponent.css';

const MyComponent = ({ items }) => {
  return (
    <div className="MyComponent">
      {items.map((item) => (
        <a className="Item" href="#">
          {item.name}
        </a>
      ))}
    </div>
  );
};

export default MyComponent ;
1 answer
1 points
Answered by:
Lily
548

Try to replace href="#" with href="/#" inside <a> element, this should fix the problem.

import React from 'react';
import './MyComponent.css';

const MyComponent = ({ items }) => {
  return (
    <div className="MyComponent">
      {items.map((item) => (
        <a className="Item" href="/#">
          {item.name}
        </a>
      ))}
    </div>
  );
};

export default MyComponent ;
0 comments Add comment
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join