58 lines
2.1 KiB
Plaintext

== Why is this an issue?
React components often render HTML elements, and developers can pass various props (properties) to these elements. However, React has its own set of supported properties and attributes, and it's essential to avoid using unknown or invalid properties when working with such elements to prevent unexpected behavior at runtime.
The rule reports any instances where you are using a property or attribute that is not recognized by React or the HTML element you are rendering.
== How to fix it
Replace any unknown property or attribute with a known one, or add it to the list of exceptions.
=== Code examples
==== Noncompliant code example
[source,javascript,diff-id=1,diff-type=noncompliant]
----
class Welcome extends React.Component {
render() {
return <div class="hello">Hello, World!</div>; // Noncompliant: 'class' is a reserved keyword in JavaScript
}
}
----
==== Compliant solution
[source,javascript,diff-id=1,diff-type=compliant]
----
class Welcome extends React.Component {
render() {
return <div className="hello">Hello, World!</div>;
}
}
----
==== Noncompliant code example
[source,javascript,diff-id=2,diff-type=noncompliant]
----
const Image = <img source={myImage} />; // Noncompliant: The 'img' tag does not recognize any 'source' attribute
----
==== Compliant solution
[source,javascript,diff-id=2,diff-type=compliant]
----
const Image = <img src={myImage} />;
----
== Resources
=== Documentation
* MDN web docs - https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes[HTML attribute reference]
* MDN web docs - https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes[HTML global attributes]
* MDN web docs - https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute[SVG attribute reference]
* MDN web docs - https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attributes[ARIA states and properties]
* MDN web docs - link:++https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/data-*++[data-*]
* React Documentation - https://react.dev/reference/react-dom/components/common#common-props[Standard DOM props]