[英]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.