React requires camelCase property names for HTML attributes that are also JavaScript reserved words. Using "class" or "for" directly in JSX will trigger a warning because "class" is used for ES6 class declarations and "for" is used in loop statements.
In JSX, certain HTML attributes conflict with JavaScript reserved keywords. "class" is a reserved word in JavaScript because it is used to define ES6 classes, and "for" is reserved because it is used in for loops and for...in statements. React prevents using these reserved words as JSX properties to avoid syntax conflicts. Instead, React uses camelCase alternatives: "className" for the HTML "class" attribute and "htmlFor" for the HTML "for" attribute. These properties are automatically converted back to their HTML equivalents when React renders to the DOM.
In JSX, you must use the className property instead of the HTML class attribute. This is because class is a reserved keyword in JavaScript used for ES6 class declarations.
Before:
<div class="container">
<p class="text-blue">Hello World</p>
</div>After:
<div className="container">
<p className="text-blue">Hello World</p>
</div>When React renders this to the DOM, the className property is automatically converted back to the class attribute in the final HTML, so browsers will correctly apply CSS styles.
For form labels that associate with input elements, use htmlFor instead of the HTML for attribute. This is because for is a reserved keyword in JavaScript used for loop statements.
Before:
<label for="username">Username:</label>
<input id="username" type="text" />After:
<label htmlFor="username">Username:</label>
<input id="username" type="text" />The htmlFor property tells React to associate the label with the input element by matching the id. When rendered to the DOM, React converts htmlFor to the standard HTML for attribute.
React requires camelCase naming for many HTML attributes, not just "class" and "for". Review your JSX code for other common attribute naming issues:
- tabindex → tabIndex
- autocomplete → autoComplete
- onclick → onClick
- onchange → onChange
- readonly → readOnly
- disabled → disabled (already camelCase)
- accept-charset → acceptCharset
- max-length → maxLength
React's linter or IDE will typically warn you about these automatically, so check your development console for any additional warnings after fixing "class" and "for".
Enable React and TypeScript linting rules to catch reserved property names before runtime:
For TypeScript:
Enable strict JSX checking in your tsconfig.json:
{
"compilerOptions": {
"jsx": "react-jsx",
"strict": true
}
}For ESLint:
Install the React plugin and enable it:
npm install --save-dev eslint-plugin-reactAdd to your .eslintrc.json:
{
"extends": ["plugin:react/recommended"],
"rules": {
"react/no-unescaped-entities": "warn"
}
}These tools will highlight invalid property names in your IDE as you type, preventing the warning from appearing in the browser console.
The reason React uses camelCase naming conventions stems from the way JSX is transpiled to JavaScript. When Babel or TypeScript compiles JSX to JavaScript, properties must be valid JavaScript identifiers. Since "class" and "for" are JavaScript reserved words, they cannot be used as property names in object literals without causing syntax errors. React chose camelCase conventions (className, htmlFor) as the JSX standard, which maps cleanly to the underlying HTML attributes at render time. The same principle applies to other HTML attributes like tabindex (tabIndex), onclick (onClick), etc. When React renders components, it automatically converts these camelCase properties to their lowercase HTML equivalents for the DOM, so the final HTML output is valid and follows HTML standards.
React Hook useCallback has a missing dependency: 'variable'. Either include it or remove the dependency array react-hooks/exhaustive-deps
React Hook useCallback has a missing dependency
Cannot use private fields in class components without TS support
Cannot use private fields in class components without TS support
Cannot destructure property 'xxx' of 'undefined'
Cannot destructure property of undefined when accessing props
useNavigate() may be used only in the context of a <Router> component.
useNavigate() may be used only in the context of a Router component
Cannot find module or its corresponding type declarations
How to fix "Cannot find module or type declarations" in Vite