Consuming JavaScript in Blazor
By this point, we have developed components to render data and capture the user’s input and written logic and navigate between pages, all purely with C#, and that’s the big promise of Blazor. But a little bit of JavaScript is kind of needed in some cases.
Throughout this chapter, we are going to discover those cases with some real-world examples, along with the IJSRuntime interface, which is a Blazor built-in service that allows communication between C# and JavaScript and vice versa.
This chapter will cover everything you need to know about JavaScript in Blazor apps:
- When and why we use JavaScript in Blazor apps
- Calling JavaScript from C# code
- Calling C# from JavaScript code
- Turning an existing JS package into a reusable Blazor component