Combining component design principles
We’ve separately analyzed the principles of single responsibility, don’t repeat yourself, and composition. However, in practical coding scenarios, things can get intricate, necessitating the simultaneous application of multiple principles to enhance the readability and maintainability of the code.
Let’s consider an example of a Page
component, which might have many responsibilities such as managing the state and behavior of a header, sidebar, and main content area. Also, there are a bunch of props for configuring each of these sections. It’s typical to encounter such code when individuals simply replicate the existing code base without much consideration or critical thinking; so the prop list grows as new features are added.
Here is a simplified example:
import React from "react"; type PageProps = { headerTitle: string; headerSubtitle: string; sidebarLinks: string...