I'm currently creating a new React application with create-react-app. After that I install eslint that extends plugin:react/recommended and google. 2 weeks ago I did the same and I had no problems but since 2 days I now get a "Missing "key" prop for element in array" error in my index.tsx and App.tsx files for each html line.
index.tsx
import './index.css';
import React from 'react';
import ReactDOM from 'react-dom';
import App from './App';
import reportWebVitals from './reportWebVitals';
ReactDOM.render(
<React.StrictMode>
<App /> <!-- Here I get a missing key prop error -->
</React.StrictMode>,
document.getElementById('root'),
);
App.tsx
import './App.css';
import React from 'react';
import logo from './logo.svg';
function App() {
return (
<div className="App">
<header className="App-header">
<img src={logo} className="App-logo" alt="logo" />
<p>
Edit <code>src/App.tsx</code> and save to reload.
</p>
<a
className="App-link"
href="https://reactjs.org"
target="_blank"
rel="noopener noreferrer"
>
Learn React
</a>
</header>
</div>
);
}
export default App;
In the App.tsx I get the missing key prop error on all lines inside the <div className="App"></div>
I have no idea why I'm getting this error but removing the plugin:react/recommended
from .eslintrc.yml removes the errors. Probably because the react/jsx-key rule is applied in that ruleset.
I'm also tried removing the eslintConfig
block frmo package.json
Extra info
Version
- Node: 16.14.0
- Npm: 8.5.2
package.json
{
...
"dependencies": {
"@testing-library/jest-dom": "^5.16.2",
"@testing-library/react": "^12.1.3",
"@testing-library/user-event": "^13.5.0",
"@types/jest": "^27.4.1",
"@types/node": "^16.11.26",
"@types/react": "^17.0.39",
"@types/react-dom": "^17.0.11",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-scripts": "5.0.0",
"typescript": "^4.5.5",
"web-vitals": "^2.1.4"
},
"devDependencies": {
"@typescript-eslint/eslint-plugin": "^5.12.1",
"@typescript-eslint/parser": "^5.12.1",
"eslint": "^8.9.0",
"eslint-config-google": "^0.14.0",
"eslint-plugin-react": "^7.29.0"
}
}
.eslintrc.yml
env:
browser: true
es2021: true
extends:
- plugin:react/recommended
- google
parser: '@typescript-eslint/parser'
parserOptions:
ecmaFeatures:
jsx: true
ecmaVersion: latest
sourceType: module
plugins:
- react
- '@typescript-eslint'
rules: {
require-jsdoc: 0
}
Any idea what is happing here and how I can solve this problem.
CodePudding user response:
This is an error coming from the rule react/jsx-key
of the plugin eslint-plugin-react
in its new release (7.29.0).
It has been reported here.
You could downgrade your version of eslint-plugin-react
to 7.28.0 until the issue is fixed.