EN
React - the href attribute requires a valid value to be accessible warning
1
answers
1
points
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
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