Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Mastering Blazor WebAssembly

You're reading from  Mastering Blazor WebAssembly

Product type Book
Published in Aug 2023
Publisher Packt
ISBN-13 9781803235103
Pages 370 pages
Edition 1st Edition
Languages
Author (1):
Ahmad Mozaffar Ahmad Mozaffar
Profile icon Ahmad Mozaffar

Table of Contents (21) Chapters

Preface Part 1: Blazor WebAssembly Essentials
Chapter 1: Understanding the Anatomy of a Blazor WebAssembly Project Chapter 2: Components in Blazor Chapter 3: Developing Advanced Components in Blazor Part 2: App Parts and Features
Chapter 4: Navigation and Routing Chapter 5: Capturing User Input with Forms and Validation Chapter 6: Consuming JavaScript in Blazor Chapter 7: Managing Application State Chapter 8: Consuming Web APIs from Blazor WebAssembly Chapter 9: Authenticatiwng and Authorizing Users in Blazor Chapter 10: Handling Errors in Blazor WebAssembly Part 3: Optimization and Deployment
Chapter 11: Giving Your App a Speed Boost Chapter 12: RenderTree in Blazor Chapter 13: Testing Blazor WebAssembly Apps Chapter 14: Publishing Blazor WebAssembly Apps Chapter 15: What’s Next? Index Other Books You May Enjoy

Controlling the rendering using the @key directive

When it comes to rendering collections by iterating over the items and rendering some UI elements, the powerful mechanism of Blazor RenderTree and its diffing algorithm will observe the changes happening to the list (insert, update, and delete) and update the UI accordingly. Blazor assigning and indexing for each item gets rendered in the UI based on the items in the list at runtime. That’s the normal approach for most cases.

Because the sequence numbers are assigned at runtime, Blazor will start sequentially from the first item in the list to the last. So, let’s create a sample component that will simulate the scenario, as follows:

  1. In the Pages folder, create a Razor component and call it key-directive-sample.razor.
  2. Write the following code inside it:
    @page "/key-directive-sample"<h3>Key Attribute Sample</h3><ul>    @foreach (var item in numbers)  ...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime}