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

时间:2018-01-02 21:27:39

标签: javascript reactjs eslint

如何在ESLint中避免此错误?我应该以不同的方式编写此代码吗?我无法更改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;

enter image description here

1 个答案:

答案 0 :(得分:8)

根本不需要props

你可以把它写成没有参数的函数:

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;