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.
We will share the code between the BlazorWebApp
project and the BlazorWebApp.Client
project. We will even change the implementation of how they run depending on whether they run as WebAssembly or not.
There is a whole chapter on sharing (Chapter 9, Sharing Code and Resources), 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. We could have added the components to the BlazorWebApp
or the BlazorWebApp.Client
project directly, but this demonstrates how we can build reusable components and distribute them...