简体   繁体   English

React中的无状态组件和“Props已定义但从未使用过”ESLint错误

[英]Stateless component in React and “Props is defined but never used” ESLint error

How can I avoid this error in ESLint? 如何在ESLint中避免此错误? Should I write this code in a different way? 我应该以不同的方式编写此代码吗? I can't change ESLint config and I should have 0 errors... 我无法更改ESLint配置,我应该有0个错误...

import React from 'react';
import logo from './logo.svg';
import './style.css';

import SearchBar from '../SearchBar';
import GithubDataTable from '../GithubDataTable';

const App = props => (
  <div className="App">
    <header className="App-header">
      <img src={logo} className="App-logo" alt="logo" />
      <h1 className="App-title">The Task</h1>
    </header>
    <div>
      <SearchBar />
      <GithubDataTable />
    </div>
  </div>
);

export default App;

在此输入图像描述

You don't need props at all. 你根本不需要props

You can just write it like a function without params: 您可以像没有参数的函数一样编写它:

import React from 'react';
import logo from './logo.svg';
import './style.css';

import SearchBar from '../SearchBar';
import GithubDataTable from '../GithubDataTable';

const App = () => (
  <div className="App">
    <header className="App-header">
      <img src={logo} className="App-logo" alt="logo" />
      <h1 className="App-title">The Task</h1>
    </header>
    <div>
      <SearchBar />
      <GithubDataTable />
    </div>
  </div>
);

export default App;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何修复 eslint 在反应中的“组件已定义但从未使用”? - How to fix "Component is defined but never used" for eslint in react? [eslint] src\App.js 第 2:8 行中的 React js 错误警告:'person' 已定义但从未使用过 - React js error WARNING in [eslint] src\App.js Line 2:8: 'person' is defined but never used @typescript-eslint/eslint-plugin 错误:定义了“路由”但从未使用过(no-unused-vars) - @typescript-eslint/eslint-plugin error: 'Route' is defined but never used (no-unused-vars) &#39;React&#39; 已定义但从未使用 - 'React' is defined but never used props.children是否会成为无状态组件? - props.children in react cannot be a stateless component? React props id 绑定到无状态组件中的 onClick - React props id binding to onClick in a stateless component 将道具传递给无状态功能组件 - React Pass Props to a Stateless Functional Component 组件已定义但从未使用 reactjs 中的 no-unused-vars 错误警告 - component is defined but never used no-unused-vars error warning in reactjs ESLint - 组件应编写为纯函数(反应优先/无状态函数) - ESLint - Component should be written as a pure function (react prefer/stateless function) “&#39;React&#39; 在定义之前就被使用了。” eslint 警告 - “'React' was used before it was defined.” eslint warning
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM