Writing our first component
The first component we will build shows all the blog posts on a site. To be fair, we haven't written any blog posts yet but we will temporarily solve that so we can start doing something fun.
In Chapter 3, Managing State Part 1, we created a JSON repository and an API (or interface); now it is time to use them.
Components with or without a page directive can be shared across different projects. By the end of this book, we will have built a blog in both Blazor Server and Blazor WebAssembly that are sharing code. There is a whole chapter on sharing (Chapter 9, Sharing Code and Resources Between Projects) but let’s start now.
Creating a components library
The first thing we need to do is to create a new project and then add our components to that project.
To create our first component, follow these instructions:
- Right-click on the MyBlog solution and select Add | new project
- Find the template Razor Class Library and click Next.
- Name the project Components...