Summary
You should now be able to create a local storage service by using JS interop to invoke JavaScript functions from your Blazor WebAssembly application.
In this chapter, we explained why you may still need to use JavaScript and how to use the IJSRuntime
abstraction to invoke JavaScript functions from .NET, both asynchronously and synchronously. Conversely, we explained how to invoke .NET methods from JavaScript functions. Finally, we explained how to store data in the browser by using the application’s Local Storage.
After that, we used the Blazor WebAssembly App Empty
project template to create a new project. We added a couple of JavaScript functions to read and write the application’s Local Storage. Then, we added a class to invoke those JavaScript functions. In the last part of the chapter, we tested our local storage service by adding a collocated JavaScript file that opened a JavaScript alert box.
One of the biggest benefits of using Blazor WebAssembly is that...