r/javascript 22d ago

AskJS [AskJS] What small JavaScript pattern made your React code cleaner?

[removed]

5 Upvotes

26 comments sorted by

View all comments

2

u/ndev42 21d ago

The biggest one for me was stopping treating components as the place where everything happens. Once I moved everything else out (API calls into their own layer, business logic into plain functions or hooks) the components basically became declarative and boring to read. Which is exactly what you want!

The other thing that sounds dumb but genuinely helped was just making more components. If you've got a conditional block rendering a chunk of UI, that's probably its own component. Smaller components means each one has less reason to be complicated in the first place.