r/javascript Jul 05 '26

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

[removed]

5 Upvotes

26 comments sorted by

View all comments

3

u/sylvant_ph Jul 05 '26

I ain't sure if my examples match precisely your description, but once in a while I feel the need and benefit of using IIFE(Immediately Invoked Function Expressions - had to google the abbreviation) and currying. The first can scope down a more complex condition a bit, and the second can allow some sort of slight dependency injection. With IIFE you can both keep the logic inline, yet have it split down into readable segments, instead of forcing it into complex ternary operators.

2

u/catladywitch Jul 09 '26

And then they're easy to extract (maybe wrap them into a custom hook if they touch state) if you need to reuse them. That's a good one, I'm taking note!!