question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

File naming conventions

See original GitHub issue

I’m trying to figure out a good file naming convention for my app and it seems like you guys have a great react style guide. There is one thing that is kind of confusing:

Use the filename as the component name. For example, ReservationCard.jsx should have a reference name of ReservationCard. However, for root components of a directory, use index.jsx as the filename and use the directory name as the component name

This sentence doesn’t really make sense to me:

However, for root components of a directory, use index.jsx as the filename and use the directory name as the component name

In your example here, it states that this is bad:

// bad
import Footer from './Footer/index';

Isn’t that “bad” example what you’re referring to when you say “for root components of a directory, use index.jsx as the filename and use the directory name as the component name”?

Can you give an example of what would go in the index file?

Thanks!

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:3
  • Comments:9 (2 by maintainers)

github_iconTop GitHub Comments

7reactions
tleunencommented, Jul 11, 2016

We talk a bit in this ticket https://github.com/airbnb/javascript/issues/817, bu one thing that I don’t like with the current convention is if I’m building a UI component library, with css attached to each component, I end up with a structure like this:

components/
    Button/
        index.js
        styles.css
    Table/
        index.js
        styles.css
    Dropdown/
        index.js
        styles.css
    Video/
        index.js
        styles.css

Sometimes it gets confusing because they all have the same file name.

3reactions
wyzecommented, Jul 11, 2016

It is considered bad because then index is unneeded in the import from './Footer/index', as it will resolve the import without it. Right below the one you quoted they give a good example without index.

// good
import Footer from './Footer';
Read more comments on GitHub >

github_iconTop Results From Across the Web

File Naming Conventions | Data Management
A file naming convention is a framework for naming your files in a way that describes what they contain and how they relate...
Read more >
File naming and structure - Research Data Management at ...
File naming best practices: · Files should be named consistently · File names should be short but descriptive (<25 characters) (Briney, 2015) ...
Read more >
File Naming Conventions - HURIDOCS
A filename can be made up of a series of descriptive elements, such as keywords, dates, identifying numbers, etc. To design a file...
Read more >
File Naming Conventions - Introduction to Data Management ...
A File Naming Convention (FNC) is a framework for naming your files in a way that describes what they contain and how they...
Read more >
File Naming Conventions: simple rules save time and effort
The file name describes, at a glance, what the document is about, making it easier to browse files more effectively and efficiently. ✓...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found