简体   繁体   English

eslint 与 airbnb 反应

[英]eslint react with airbnb

eslinting with airbnb用 airbnb 偷偷摸摸

import React from 'react';
import TopBar from './topBar';
import Content from './content';

class App extends React.Component {
  render() {
    return (
      <div className="app">
        <TopBar />
        <Content />
      </div>
    );
  }
}

export default App;

gives the error给出错误

5:1  error  Component should be written as a pure function  react/prefer-stateless-function

I have tried我试过了

function render(){}

and

render: function() {}

but didn't succeed但没有成功

Using the docs from https://facebook.github.io/react/docs/reusable-components.html#stateless-functions , your code sample would be converted to:使用https://facebook.github.io/react/docs/reusable-components.html#stateless-functions 中的文档,您的代码示例将转换为:

import React from 'react';
import TopBar from './topBar';
import Content from './content';

function App (props) {
  return (
    <div className="app">
      <TopBar />
      <Content />
    </div>
  );
}

export default App;

Note that this updated code sample will break some other airbnb eslinting rules but those should be self-explanatory.请注意,此更新的代码示例将破坏一些其他的 Airbnb eslinting 规则,但这些规则应该是不言自明的。 Just posting this as a template to follow.只需将此作为模板发布即可。 The docs on this subject are very direct so make sure you give those a good review.关于此主题的文档非常直接,因此请确保对这些文档进行良好的评论。

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

相关问题 没有eslint插件反应的ESLint + Airbnb - ESLint + Airbnb without eslint-plugin-react 使用 React 和 Webpack 设置 Airbnb ESLint - Setting up Airbnb ESLint with React and Webpack Eslint(Airbnb)缩进问题与React代码(JSX) - Eslint (Airbnb) indentation issues with React code(JSX) Intellij 插件:带 React 的 AirBnB ESLint - Intellij plugin: AirBnB ESLint w/ React 将 ESLint 与 Airbnb 样式和选项卡 (React.js) 结合使用 - Use ESLint with Airbnb style and tab (React.js) 更漂亮的 eslint:使用 &#39;prettier&#39; 或 &#39;plugin:prettier/recommended&#39; 和 React Typescript airbnb eslint 配置 - Prettier eslint: use 'prettier' or 'plugin:prettier/recommended' with React Typescript airbnb eslint config 如何配置 eslintrc 并将 React 添加到 eslint(使用 airbnb、typescript)而不创建 react 应用程序 - How to configure eslintrc and add React to eslint (with airbnb, typescript) without create react app Eslint - 找不到 eslint-config-airbnb - Eslint - eslint-config-airbnb not find 在react.js中使用eslint-config-airbnb时,“ fetch”是未定义的,“ localStorage”是未定义的 - “fetch” is undefined and “localStorage” is undefined , on using eslint-config-airbnb in react.js 解决似乎没有意义的ESLint / React / Redux(Airbnb配置)错误 - Resolving ESLint / React / Redux (Airbnb config) errors that don't seem to make sense
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM