Revisiting the Single Responsibility Principle
In Chapter 4, we delved into the SRP within the context of designing React components. Yet this principle is more universal, acting as the bedrock for various other programming tenets. To bring this idea to life, let’s work through some hands-on examples.
Identifying the core responsibility of a component is key to adhering to the SRP. Once you isolate what the component is fundamentally meant to do, it becomes easier to refactor and abstract out auxiliary functionalities.
The SRP, being a high-level guideline, is advantageous when applied directly at the code level. There are numerous ways to implement this principle, but recognizing when to apply it is crucial, especially as complexity increases.
The most common two techniques we’ll use are render props and composition. Render props refer to a technique in React for sharing code between components using a prop whose value is a function. A component with a render...