skip to Main Content

I am playing around with the ReactJS and i have noticed that name of file which export components always upper case. For example file that contain Book component ( i’m working with book list) name Book.js. Naming the file export components by starting with uppercase letter is convention of Reactjs Community or this is the rule of reactjs library

Can i name the file that export Book component is book.js or b.js ? and this is may cause any implicit errors or not match with the rule of reactjs

2

Answers


  1. There is no rule as such. Different orgs follow different conventions when it comes to file names. But it is definintely required that custom components should start with a CAPITAL alphabet. Lower case is used for standard HTML Elements like div, span etc.

    Docs

    Login or Signup to reply.
  2. In React, there are no specific rules or conventions regarding the naming of files for components. You can name the file that exports the Book component as book.js, b.js, or any other valid filename you prefer.

    However, it is generally recommended to use meaningful and descriptive names for your files and components to enhance code readability and maintainability. Using a name like book.js would be more descriptive and easier to understand than b.js. It’s always a good practice to choose names that accurately represent the purpose or functionality of the component.

    While there are no implicit errors or technical issues associated with using different filenames, it’s essential to maintain consistency across your codebase. Consistent naming conventions make it easier for you and other developers to navigate and understand the project. So, consider following a naming convention that suits your project and stick to it consistently.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search