7 Creating more reusable components
This chapter covers
- How templates can be used to define specific regions of UI
- Enhancing templates with generics
- Sharing components using Razor Class Libraries
Reusability is one of the compelling reasons for using components. They allow us to define chunks of markup and logic which can be reused by simply referencing them in other markup. This is an immensely powerful tool indeed. So far, we’ve taken advantage of this on several occasions in previous chapters:
- TrailCard component
- FormSection component
- FormFieldSet component
- SuccessAlert & ErrorAlert components
In this chapter, we’re going to take reusability to the next level. We’re going to learn how to leverage templates and generics to make the ultimate reusable components. To give us a practical example, we’ll be enhancing the home page of Blazing Trails with a component which allows the user to toggle the layout between a grid and a table (figure 7.1).
Figure 7.1 Shows the home page of Blazing Trails with the final ViewSwitcher component we’ll be building during this chapter. The component allows the user to toggle between a grid view and a table view of the available trails.
