Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

File naming conventions in reactJS?

Tags:

reactjs

Recently, I have started learning ReactJS. The only thing that confuses me is naming folders and files in the React app directory.

  • To name component files, some people follow TitleCase.js and some follow camelCase.js.

  • To name app directories, few people follow camelCase and few smallcase or small-case.

I tried to find the official documentation on naming conventions but couldn't. Can someone help me find the right way of naming files in ReactJS?

like image 880
Narasimha Reddy - Geeker Avatar asked May 15 '17 06:05

Narasimha Reddy - Geeker


People also ask

What are naming conventions for files?

A File Naming Convention (FNC) is a framework for naming your files in a way that describes what they contain and how they relate to other files. Developing an FNC is done through identifying the key elements of the project, the important differences and commonalities between your files.

How do I organize files in React?

Open the component's file and start editing away. Then you need to edit your styles, so you also navigate to your styles folder, find the button and open that. Now the component is updated, the tests are broken and some stories need to be updated. You navigate to those respective folders and open tests/button.


2 Answers

Regarding naming conventions, ReactJS is unopinionated.

There isn't an official guideline or statement about the questions you raised. You won't find them in the documentation either.

It's a personal (team) preference. If you struggle to enforce one, you could stick to something like Airbnb's mostly reasonable approach to React and JSX.

PS: As long as you're consistent, I would say you're safe.

like image 100
Kaloyan Kosev Avatar answered Sep 23 '22 02:09

Kaloyan Kosev


Based on 'Google JavaScript Style Guide'

File names must be all lowercase and may include underscores (_) or dashes (-), but no additional punctuation. Follow the convention that your project uses. Filenames’ extension must be .js.

like image 36
Vlad Bezden Avatar answered Sep 23 '22 02:09

Vlad Bezden