Practices - Do you write small components?

Last updated by Caleb Williams [SSW] 2 months ago.See history

The Single Responsibility Principle is a well understood, and well-accepted tenet of good code design. It states that a class should do one thing, and do it well - The same applies to Components used with Frameworks such as Angular, React, Vue and Blazor.

When designing components, keep them small, modular and reusable. For example, if you have a menu, put it into a menu component, don’t put it in your app component.

comp 1
Figure: Bad example - Having just 3 components for the page makes it difficult to reuse, maintain and test

comp 2
Figure: Good example - Splitting up the page into 11 components means they are small and targeted - and thus easy to maintain and test. Components can be reused on other pages

We open source. Powered by GitHub