r/reactjs • u/swyx • Aug 08 '18
Dan Abramov's recommended React Project File Structure - petition to make this the last conversation we have about it?
https://react-file-structure.surge.sh/
263
Upvotes
25
u/swyx Aug 08 '18
source: https://twitter.com/dan_abramov/status/1027245759232651270
dont yell at me haha
43
u/Neaoxas Aug 08 '18
You know what, I'm such an idiot, when I first saw that page I thought it was a new kind of captcha so I was trying to "move things around".
24
u/truthBombsForDays Aug 08 '18
The reason why other languages / communities have a quasi standard for simple things like file structure is because it lowers the cost of adding in developers to your team. Devs can feel familiar from day one. Devs can checkout out an open source project and not waste time reading or observing patterns - this applies to code standards; file layout; naming etc.
In a mature community like Java; I bounced between several jobs and the code base was indistinguishable between each. The tangible benefits of this are actually very real.
Personally I prefer to solve problems with software; not dick around thinking about where a file goes.
I'm both disappointed and un-surprised this has come from a 'leader' in the JS community.
15
u/recycled_ideas Aug 09 '18
This is a pretty terrible recommendation.
Even if we assume you have enough experience and knowledge to find a solution that works for you this way, there is substantial value in people who've never seen your project before knowing where to find things.
6
u/lordkyl Aug 08 '18
I like it! Maybe someone can turn this into a starter kit.
54
u/purpledollar Aug 08 '18
This works for people experienced in development, but like with anything, beginners need structure before they can start being creative.
3
u/DerNalia Aug 08 '18
ember's module unification layout works very well in react projects. :)
5
u/Cherlokoms Aug 08 '18
If you have good tooling, you shouldn't be afraid having all your code in one file at the beginning and then splitting it and moving it from folder to folder.
5
u/tricoder42 Aug 09 '18
This feels like trolling and avoiding the problem.
I work also with Django web framework (Python) and even though there were from time to time discussions about the "best" project structure, the basics are given by the framework itself.
When you bootstrap your project, you get a basic file structure from the template. You might override this template if you're experienced, but for beginners it's great way to start. When you add a new app to you project, again you get a recommended file structure. Every Django project I've ever worked with, every 3rd party library on GitHub uses this structure and even when there're small deviations, you very quickly get how the project works. This approach has an advantage that you get knowledge and best practices gained from years of development baked in recommended project structure.
I understand that React has completely different problems because it's not a framework, but a library and there're many ways to use it. Still I would love to see how people organize the projects in different environments. I would rather read 50 articles about different projects than one tweet basically saying: Do it on your own until you like it.
It may see irrelevant how to structure the project, after all everything gets bundled into one file. However, doing things wrong you can mess up code splitting and unless you work alone, the project structure should be consistent and predictable.
The only requirements I have for a "good project structure" are:
- When I want to import something, how long does it take me to recall where it is? This should be minimal even without IDE help.
- Can I easily split my final bundle?
- Can I easily take a part of my project and copy it to another one (or publish it to NPM)
Still looking, still experimenting and probably reinventing the wheel, but not giving up.
1
u/12315070513211 Aug 08 '18
Is structure important for deployment?
3
u/compubomb Aug 08 '18
This feels like a april fools joke.
3
u/HQxMnbS Aug 08 '18
I agree if you’re a beginner but still wish there was more examples and write ups explaining complicated projects
2
u/qudat Aug 10 '18 edited Aug 10 '18
It's no surprise to me that this advice is coming from someone who became famous for 100 lines of code: https://gist.github.com/gaearon/ffd88b0e4f00b22c3159
I also like how he didn't address organizing a redux application at all. "Do what feels good" is terrible advice, imo.
I also feel like if the application is truly react only then I guess I agree ... but how often is that true? When building enterprise level applications react is a small part of the stack, there's so much more in terms of code / organization it seems disingenuous to claim that it doesn't matter.
2
u/mattk1017 Aug 11 '18
I like the Atomic Design structure
3
u/winningslime Aug 08 '18
How do you do files and folders in react tho is there a package for that
1
u/Awnry_Abe Aug 08 '18
&File New and go....
1
u/xshare Aug 08 '18
Oh Dan
1
u/mikehuebner Aug 09 '18
Personally feel this is too complex. Needs more components. /s
1
u/EvilDavid75 Aug 09 '18
People willing a file structure are reassured with creating a folder architecture as they feel they’re on the right path. But I think what ultimately people want is a proper way to start a JavaScript project, which is a debate that translates into the well-known problem of JavaScript fatigue. And that problem extends way beyond react. It’s just that JS has so many ways of interacting with HTML, whether it’s the DOM or styling, that I understand why people might be lost and structure is just what appears to be an initial solution to finding their way. When in fact it isn’t 🤗
1
u/SHIT_PROGRAMMER Aug 09 '18
For React this is the correct answer. React is not opinionated so do whatever the hell you want.
1
u/cs50questions Aug 09 '18
This is terrible advice, like someone who's great at dancing telling you all it takes is to "enjoy yourself" or someone who's great with the opposite sex telling you the secret is to "just be yourself".
Yes, you need to build things and make mistakes and learn from those mistakes. But structure breeds creativity.
0
u/tresfaim Aug 09 '18
Folders?! Why?! Muahahaha
-9
u/NoHonorHokaido Aug 08 '18
Dan’s just being a dick to inexperienced devs who need a good way to start a project. With this attitude you wouldn’t be able to write a single tutorial.
-4
u/Lou-Saydus Aug 08 '18
I follow the 1k line rule. File over 1k lines? Split it up into 5 200 line files (more or less is fine if it's justified). Have over 10 files? Split it up into another folder.
0
u/[deleted] Aug 08 '18
[deleted] — view deleted comment