Naming Best Practices for React Components and Functions Including Filenames
Answer a question
I notice that a lot of projects name their react components with uppercase class names and lowercase filenames. Why would that be different?
Answers
I believe that would not be the best practice. The filename should be the same as the React component's, and should be written in PascalCase.
For instance: Navigation.jsx exports Navigation
Further reading about naming conventions:
- Stackoverflow question
Bonus: Structuring files and folders in a React project:
-
Yay, Hackernoon again!
-
Alexis Mangin's post
-
You probably don't need to read this if you don't use redux, but it has a good comparison between function-first and feature-first grouping techniques. Alex Moldovan's post
Edit: From nextjs official website
Next.js will serve each file in
/pagesunder a pathname matching the filename.For example,
/pages/about.jsis served atsite.com/about.
Therefore in case of Nextjs, they wanted to separate component and page files as page files are used for routing.
更多推荐
所有评论(0)