admin管理员组文章数量:1319022
I am trying to find the best naming convention for ponents in a React.js app. This is how I have currently been doing it...
Imagine I have a searchBar ponent that I want to render in my table ponent.
search-bar.js
var React = require('react');
var SearchBar = React.createClass({
/* code for search ponent */
});
module.exports = SearchBar;
table.js
var React = require('react');
var SearchBar = require('search-bar');
var Table = React.createClass({
render: function() {
return (
<SearchBar />
);
}
});
module.exports = Table;
Is this naming convention okay or is it standard?
- hyphen-delimited for ponent file names
- PascalCase for the ponent function declarations.
I am trying to find the best naming convention for ponents in a React.js app. This is how I have currently been doing it...
Imagine I have a searchBar ponent that I want to render in my table ponent.
search-bar.js
var React = require('react');
var SearchBar = React.createClass({
/* code for search ponent */
});
module.exports = SearchBar;
table.js
var React = require('react');
var SearchBar = require('search-bar');
var Table = React.createClass({
render: function() {
return (
<SearchBar />
);
}
});
module.exports = Table;
Is this naming convention okay or is it standard?
- hyphen-delimited for ponent file names
- PascalCase for the ponent function declarations.
2 Answers
Reset to default 7In a general sense it seems that react is young enough that there aren't yet many particularly strong style conventions, but what you've outlined is reflective of what I've seen for the most part. The react docs all PascalCase their ponent names and if there is in fact a style convention for module file names hyphen delimited seems far and above the most mon.
This is widely adopted naming convention and works just fine. Also, if you are struggling with ponent's name, take a look at its root HTML element class name. I found this a great way.
本文标签: javascriptcorrect naming specification for react componentsStack Overflow
版权声明:本文标题:javascript - correct naming specification for react components - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742051431a2418082.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论