I'm a front-end developer with almost 4 years of experience, working mostly with React. Today I wanted to practise and build a Select Component in React. I was looking for some inspiration and found this:
These components are +1000 lines of code long (and I know there are more examples out there, and not only involving Select Components).
I'm a pessimist so I think I'm just bad at this, but I have some hope that maybe they're doing something wrong. How could anyone (for contributing or debugging reasons) read all those lines and understand everything that's going on?
What do you think?
Top comments (4)
I believe in huge open-source projects lots of lines just cover some Github issues and edge cases that you would rarely need to cover in your app. But most definitely there are going to be some edge cases you would definitely need. And you'll find them in a hard way. So the thing is you will never know for sure what exactly you need in advance.
Yeah, I think this is the right answer.
If you were making your own component, it would be a few lines long to do what you needed.
If you are making a component that the entire world uses:
It's normal to not understand anything that's going on at first when looking at projects like those :).
Lines can be a noisy way to look at the complexity of a module or component. I'd look at the complexity first in terms of:
What you'll find is that the two work inversely to each other, and that by breaking up a component into smaller functions (hooks, components, utils, ect.) you increase the dependencies that code needs to work.
There is a way to handle both of these concerns simultaneously, and that is to write more generalized code. This allows you to break things up without introducing as many explicit dependencies between things. This introduces another measure of complexity though:
The way to handle this axis of complexity is to put more into the code, like using TypeScript over JavaScript, or writing unit tests. You can also document abstractions, but this can get out of date, and so being careful about introducing abstract ideas into the code is usually helpful.
That's just my thinking, and I'd have to look at an example to have a solid opinion whether 1000 lines of code is the right balance of all these ideas. Share a link and I'll skim it!
I didn't see the links in your post! So here's what I would say briefly. If you look at react select for example:
Would I break this up into more modules? I think that would depend on the time available, but ideally I think it could have more dependencies at the benefit of being less individually complex in my opinion. Hope that helps!