最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - correct naming specification for react components - Stack Overflow

programmeradmin2浏览0评论

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.
Share Improve this question asked Mar 20, 2015 at 0:47 svnmsvnm 24.4k23 gold badges94 silver badges109 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 7

In 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.

发布评论

评论列表(0)

  1. 暂无评论