[英]eslint react 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;
给出错误
5:1 error Component should be written as a pure function react/prefer-stateless-function
我试过了
function render(){}
和
render: function() {}
但没有成功
使用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;
请注意,此更新的代码示例将破坏一些其他的 Airbnb eslinting 规则,但这些规则应该是不言自明的。 只需将此作为模板发布即可。 关于此主题的文档非常直接,因此请确保对这些文档进行良好的评论。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.