DEV Community

Discussion on: Stop Building Your UI Components like this❌

Collapse
 
jacopkane profile image
Furkan Tunalı

I still have doubts using context instead of passing props explicitly is more elegant.

It's just another way of creating abstraction while trying to avoid a simpler abstraction.

While passing props abstraction here is, primitive and obvious (it's literally just passing parameters to another function) context is not, it requires further knowledge and documentation read and not idiomatic.

To simplify passing props, we can consider passing repeating parameters with a spread/rest operator and pass only the changing parameters. This way you can reduce repeating defining props repeatedly but will be still easier to reason where and how those parameters are coming from.

Still, thanks for this article and sharing your knowledge with other ways to approach problems.

Collapse
 
harshkc profile image
Harsh Choudhary

Sorry but I disagree with your point, even when you are passing the props you need to manage state of the props yourself. Maybe you are manging in the parent component which will become clumsy because let's say some other state of the parent rerender the whole component will re-render which will render your reusable component because props changed.

Managing state locally in reusable component helps you with not only readabliity but also with performance plus you can memoize stuffs easily.