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.
Replace any unknown property or attribute with a known one, or add it to the list of exceptions.
class Welcome extends React.Component {
render() {
return <div class="hello">Hello, World!</div>; // Noncompliant: 'class' is a reserved keyword in JavaScript
}
}
class Welcome extends React.Component {
render() {
return <div className="hello">Hello, World!</div>;
}
}
const Image = <img source={myImage} />; // Noncompliant: The 'img' tag does not recognize any 'source' attribute
const Image = <img src={myImage} />;
This rule does not apply to files that import runtime values from @stencil/core, such as the JSX factory h. Stencil JSX
uses HTML attribute spellings rather than React properties. Import aliases and combined imports also activate this exception; h does not
need to be called explicitly.
This rule also does not apply when a leading block comment specifies @jsxImportSource @stencil/core, unless the effective
@jsxRuntime is classic. This pragma-based exception does not require a runtime import from Stencil.
Type-only Stencil imports and a Stencil dependency elsewhere in the project do not activate the exception by themselves. React files in the same project remain checked.
import { h } from '@stencil/core';
const SearchField = () => <input class="search-field" tabindex="0" />;
/** @jsxImportSource @stencil/core */ export const SearchField = () => <input class="search-field" tabindex="0" />;
No issue is raised for the following framework-specific JSX properties when the corresponding integration is used:
jsx and global with Next.js or styled-jsx;css with Compiled, Emotion, or styled-components;sx with Theme UI or StyleX;tw in files that use the JSX APIs from Next.js Open Graph, Vercel Open Graph, Satori, or twin.macro.Other unknown properties are still reported.
import styled from 'styled-components';
const Button = () => (
<button css={{ color: 'red' }}>Save</button>
);
import { ImageResponse } from 'next/og';
const image = <div tw="flex items-center">Hello</div>;