DEV Community

Discussion on: ReactJS: Component everything or not?

Collapse
 
stereoplegic profile image
Mike Bybee

Yes, 100+ lines is fine, but much beyond that should be a candidate for splitting up even if only for readability's sake.

Collapse
 
cullophid profile image
Andreas Møller

It really depends on the specific case. If you end up having to switch between 3 different component every time you make a change, it is probably better to keep it as one.

Thread Thread
 
stereoplegic profile image
Mike Bybee • Edited

Unless it's variables and methods for that component (which could be evidence that it's time to break out into custom hooks, and/or convert a class component - which I don't write anymore if at all possible - to functional with hooks), I try to keep it on one screen without scrolling as much as possible.

Imports make it easy to follow what is where, and just because you can see it all in one file doesn't mean you're not repeating yourself somewhere else. It's also easier to see exactly what is causing errors when you have them split up.

And as I said about someone else looking toward future reuse, you never know when you might need that exact same component in another project, and your components in your current project could very well be the basis for a whole, independent component library.